From nobody Sun Feb 8 03:58:13 2026 Received: from mail-vs1-f52.google.com (mail-vs1-f52.google.com [209.85.217.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6979533BBB9 for ; Sun, 18 Jan 2026 15:44:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.217.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768751105; cv=none; b=aqoihSEJvNSehKusumYbAIWojCXbQsm/jHEEwrWPcjFKsg2YT5j66PP1OHTsuIdufaT/UcyZg994iI+i9CRGUwVFGmYNrwJM2Yn8+1phHmOHeSYHNkpS4MKzEGHUZsr01FFaLjDfoDnk0Tsx69ilWA03PUtwtCvZPXyCfK6Nxk0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768751105; c=relaxed/simple; bh=BtNIOm3WFxuBN0I59Ylb15JT2dcPZJy+ODhgAT4Nc5Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=meka0nADev1rpvLcgVp+MtIOMJXNQyr98obwflY3lOZWqfyQr37T2Xf5Cs7XWfJpIPZutM+YjJyulImQN7J/HTpEqOPAFjD/U13J2N4i8N8SLmoDpp3XZvgsR2UGskcyt5SZQk/X2QR+kZ110efgS/+d0dGH+bqCby8PqfQJ/tQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=C+m9xQrp; arc=none smtp.client-ip=209.85.217.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="C+m9xQrp" Received: by mail-vs1-f52.google.com with SMTP id ada2fe7eead31-5eea31b5cb7so1204009137.0 for ; Sun, 18 Jan 2026 07:44:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768751096; x=1769355896; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Ml0Pxh1qVbQteTW8hQLYuo6bKN3PZO7AtXRgiPy9iHM=; b=C+m9xQrpiMphSENRXz8B9ivFS/QWpj+7XOa1X2QDYjFN7h20DxJtwTs+V5IyiQSrU/ cUOkYVg3X/+V5t7PSruGU47aapIZPfuBjfvRVXkN7JT6RkxiNB+OaErF3jmOau94tpP1 UQzqrm5XBvCqWQZrcPowWlyhxulOtdZKGMe8uQ5hzOndcjV1NNJVraPSDm35ud3XIuS5 DrezawrlarMAkbvmbjY46OAGErEzsxvrdVxDAFKnqm2r7wuDuuDdDIg8dpRapLJstRul gq76Jk7Sh8JDvj+KgIWitOByafBP8L6T+872MX3+IcZRSS5KTsGc0moWjP5Ha75lZgJl 7H9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768751096; x=1769355896; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=Ml0Pxh1qVbQteTW8hQLYuo6bKN3PZO7AtXRgiPy9iHM=; b=hhCJkOLZ3T7G2qIh98nam8KA5WbewhlCMDPT0K/LLtAHU90tLhNVvJwx3LskMZ068g fOs2rRn9MwjZhutwze5D5n32hqPTKxvI6Zp0JdB49wqzDacmYmViAvqiPB7RePTjP7nM dgcm7HufX06HEfjai+bhypm1ttZEj/ghoy7MAIq7I4HNRtwi9TUhG0isv746/4fTm8iX lLVPDCeIDPKLb3+rmebpSP/8h5/FcjKLvglfJ+v4gW4X87AjF93iChv4heLmYN7/c/eh sK6iFw1JJiDRULeY7PLWAxrNBsQdpvoLzNaLXrliqzeLVRZh2B3ZX4YCrUsG7OizBmMz wbDQ== X-Forwarded-Encrypted: i=1; AJvYcCX6gjPOQDWqKB3SM8L3r6XPjG1caOiniK5txFwLkfNQxVZueDh84OD9jvyZAeQNh36YSMoi1fK9rS36qCo=@vger.kernel.org X-Gm-Message-State: AOJu0YynFLlnrM4aZnP4LmMBfR/rlYdWqmluuSqXFQDD2Sc13HcGuvj8 rqlVVyQa3QBheGkOtDGcWxSKVVnCEw9gz30X0FIaMFF/qb/JlD9csIN7 X-Gm-Gg: AY/fxX6KW3OTL5yfTpBO3vLEw20FYtBKSxtwaS/KcGXeIVkYpyu5uQtS+O4fcWqxrL0 Z6TN7E5zu4ZhK8H2Hs9ACJ9l62ylPW+YIEYk/202EgDSWcRQUz6RWZAezU2LlcEr5+cg5bsixw9 VIQB4YnoutA9TnxoUy4X0PGpYOy2JSG27fwWLr7OabE8CfE/dSWBdxuY/DCPqyUSdTbdxgEvQLt 761EsYEVFWJySHbxsMMuNCAMtBwCo6brl+swezUJM6CjWu7tNm7vlsQ3k9+DrszOn1jRpHfFOWz lpZQ5uH2wCN3SLAIxDCPtMApBO0qRi4T+L7XWLkk1OQ44C8ox5Bh+1NpQBA7M+kJwrCP//gUMZF Eoj+ZnmFm16TOrEeKLFRo+CjjzwT9kQ0BJDrj4Zl0dKCewXhPDp9dwrJEAsxWpUx2VkA+f3hFil MMUTYOYRds0RFz X-Received: by 2002:a05:6102:cc6:b0:5db:20ea:2329 with SMTP id ada2fe7eead31-5f1a55a32demr2588543137.35.1768751096351; Sun, 18 Jan 2026 07:44:56 -0800 (PST) Received: from [192.168.100.253] ([2800:bf0:82:11a2:7ac4:1f2:947b:2b6]) by smtp.gmail.com with ESMTPSA id ada2fe7eead31-5f1a6d3ca2esm2832731137.10.2026.01.18.07.44.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Jan 2026 07:44:56 -0800 (PST) From: Kurt Borja Date: Sun, 18 Jan 2026 10:44:29 -0500 Subject: [PATCH v4 2/7] iio: core: Refactor iio_device_claim_direct() implementation Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260118-lock-impr-v4-2-6c8d0aee8ed2@gmail.com> References: <20260118-lock-impr-v4-0-6c8d0aee8ed2@gmail.com> In-Reply-To: <20260118-lock-impr-v4-0-6c8d0aee8ed2@gmail.com> To: Andy Shevchenko , Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Benson Leung , Antoniu Miclaus , Gwendal Grignou , Shrikant Raskar , Per-Daniel Olsson Cc: David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko , Guenter Roeck , Jonathan Cameron , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, chrome-platform@lists.linux.dev, Kurt Borja X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=4534; i=kuurtb@gmail.com; h=from:subject:message-id; bh=BtNIOm3WFxuBN0I59Ylb15JT2dcPZJy+ODhgAT4Nc5Q=; b=owGbwMvMwCUmluBs8WX+lTTG02pJDJk5/z+wxcZe++GxJsk/YC7XGpWXe/l+8zZ+cni59h2ru cn1xMa/HaUsDGJcDLJiiiztCYu+PYrKe+t3IPQ+zBxWJpAhDFycAjCRmE2MDKfmP7TTmsjW0fV8 R6zIjPcvp3xqLEyqEp6TzXadVUiJsZLhn+ZPKzel0o8i9Ztd1JdkLHWIk2hWqrXgU3izrkA+VOU pJwA= X-Developer-Key: i=kuurtb@gmail.com; a=openpgp; fpr=54D3BE170AEF777983C3C63B57E3B6585920A69A In order to eventually unify the locking API, implement iio_device_claim_direct() fully inline, with the use of __iio_dev_mode_lock(), which takes care of sparse annotations. Reviewed-by: David Lechner Reviewed-by: Nuno S=C3=A1 Signed-off-by: Kurt Borja --- drivers/iio/industrialio-core.c | 44 -------------------------------------= ---- include/linux/iio/iio.h | 40 ++++++++++++++++++++++++++----------- 2 files changed, 28 insertions(+), 56 deletions(-) diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-cor= e.c index 9693a6bb3917..83078285cd97 100644 --- a/drivers/iio/industrialio-core.c +++ b/drivers/iio/industrialio-core.c @@ -2201,50 +2201,6 @@ void __iio_dev_mode_unlock(struct iio_dev *indio_dev) } EXPORT_SYMBOL_GPL(__iio_dev_mode_unlock); =20 -/** - * __iio_device_claim_direct - Keep device in direct mode - * @indio_dev: the iio_dev associated with the device - * - * If the device is in direct mode it is guaranteed to stay - * that way until __iio_device_release_direct() is called. - * - * Use with __iio_device_release_direct(). - * - * Drivers should only call iio_device_claim_direct(). - * - * Returns: true on success, false on failure. - */ -bool __iio_device_claim_direct(struct iio_dev *indio_dev) -{ - struct iio_dev_opaque *iio_dev_opaque =3D to_iio_dev_opaque(indio_dev); - - mutex_lock(&iio_dev_opaque->mlock); - - if (iio_buffer_enabled(indio_dev)) { - mutex_unlock(&iio_dev_opaque->mlock); - return false; - } - return true; -} -EXPORT_SYMBOL_GPL(__iio_device_claim_direct); - -/** - * __iio_device_release_direct - releases claim on direct mode - * @indio_dev: the iio_dev associated with the device - * - * Release the claim. Device is no longer guaranteed to stay - * in direct mode. - * - * Drivers should only call iio_device_release_direct(). - * - * Use with __iio_device_claim_direct() - */ -void __iio_device_release_direct(struct iio_dev *indio_dev) -{ - mutex_unlock(&to_iio_dev_opaque(indio_dev)->mlock); -} -EXPORT_SYMBOL_GPL(__iio_device_release_direct); - /** * iio_device_claim_buffer_mode - Keep device in buffer mode * @indio_dev: the iio_dev associated with the device diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h index aecda887d833..f6d494065efe 100644 --- a/include/linux/iio/iio.h +++ b/include/linux/iio/iio.h @@ -664,31 +664,47 @@ int iio_push_event(struct iio_dev *indio_dev, u64 ev_= code, s64 timestamp); =20 void __iio_dev_mode_lock(struct iio_dev *indio_dev) __acquires(indio_dev); void __iio_dev_mode_unlock(struct iio_dev *indio_dev) __releases(indio_dev= ); -bool __iio_device_claim_direct(struct iio_dev *indio_dev); -void __iio_device_release_direct(struct iio_dev *indio_dev); =20 /* * Helper functions that allow claim and release of direct mode * in a fashion that doesn't generate many false positives from sparse. * Note this must remain static inline in the header so that sparse - * can see the __acquire() marking. Revisit when sparse supports - * __cond_acquires() + * can see the __acquires() and __releases() annotations. + */ + +/** + * iio_device_claim_direct - Keep device in direct mode + * @indio_dev: the iio_dev associated with the device + * + * If the device is in direct mode it is guaranteed to stay + * that way until iio_device_release_direct() is called. + * + * Use with iio_device_release_direct(). + * + * Returns: true on success, false on failure. */ static inline bool iio_device_claim_direct(struct iio_dev *indio_dev) { - if (!__iio_device_claim_direct(indio_dev)) - return false; + __iio_dev_mode_lock(indio_dev); =20 - __acquire(iio_dev); + if (iio_buffer_enabled(indio_dev)) { + __iio_dev_mode_unlock(indio_dev); + return false; + } =20 return true; } =20 -static inline void iio_device_release_direct(struct iio_dev *indio_dev) -{ - __iio_device_release_direct(indio_dev); - __release(indio_dev); -} +/** + * iio_device_release_direct - Releases claim on direct mode + * @indio_dev: the iio_dev associated with the device + * + * Release the claim. Device is no longer guaranteed to stay + * in direct mode. + * + * Use with iio_device_claim_direct(). + */ +#define iio_device_release_direct(indio_dev) __iio_dev_mode_unlock(indio_d= ev) =20 int iio_device_claim_buffer_mode(struct iio_dev *indio_dev); void iio_device_release_buffer_mode(struct iio_dev *indio_dev); --=20 2.52.0