From nobody Sun Feb 8 16:31:22 2026 Received: from mail-vk1-f171.google.com (mail-vk1-f171.google.com [209.85.221.171]) (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 6A5E8374178 for ; Tue, 20 Jan 2026 06:21:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768890078; cv=none; b=kNzfAuHkyYlQSTI29KZyGqM8riED8jFUQVaOMmhsipD28R3qbOOSrf6Vzyjy4mBR+KAMrS0Oj+Ye4Ra/obpnSHdLK0354WwQGxY3n1EwiPEw1gkuxHoduW4PWOIS051C2XYQES8YFbWlY61hjqYc3PDu+xa2KsK+3j1wf2gLDQU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768890078; c=relaxed/simple; bh=vf6b08yM9ZBa2hmugn0zaME77U5lLecJX0FGGC0bIPo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RuK+JLRUwUEeEsWukv/Rj9xJ4RSQzRFnSEIENSmGivOtJXd/fcZ0564uvzokIcVoLwXKN+QZf1cMq1njK+RXBK3ZO5IT34p8kzewtK0RYiwgz3nx1FO8HP//sUK4FYhYbwJ1+yqqS7yNX2lm3d/JsnNRuYjLJcZpxhVvjidFuMw= 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=WsZOHxUh; arc=none smtp.client-ip=209.85.221.171 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="WsZOHxUh" Received: by mail-vk1-f171.google.com with SMTP id 71dfb90a1353d-563686df549so3934867e0c.1 for ; Mon, 19 Jan 2026 22:21:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768890075; x=1769494875; 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=UKZCOUdlyM96S2jf/HyAYyFcxZYAitp5mesgIJsfK4E=; b=WsZOHxUhnXFH2GwCloPOTOSdNG2QYdQB7NzZOt5fJpnvA3Jy4BmYcPIm5nhCzdqUPx sfmD6LZitwZccev2CJZEKtxee+MJLiD6CxPXoBuosl3dsiozzpI2z7JKxunMETxoJN4V yQsHPs5LmiUlZRP1pHlSjpyh6YZvtb8Gq7BluhSqknA7Xgq9mVjLQVQEsZWMmOW+9SbD r+nP/+aVBLO3yicSmG2I4btYEVQyh1QYvNMU4gFgOsL7TSXYurzpFTFntGtqTKVG9ixn rXVMr4h6MxalFzKy3mScxSHJ/e1R72PQhGZJuZ6F8a7XjpC944dxAsx5DalmD1p/QAPK lJ0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768890075; x=1769494875; 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=UKZCOUdlyM96S2jf/HyAYyFcxZYAitp5mesgIJsfK4E=; b=ayrBQZwzeQCN40vryFsTMeqT8Ga8j4gdmghD3XUvT/6dKOaPFLWi/8yvX9BVamJlN0 A8NIbRwti9jKRrJRTUAkV92rQh7UsiB+Y6WurQyerkS9gGWhSJsvPTrHgtmiGb5AGUvE jIu4+f0uSJr84C6l7IPozptIIMD7mh+lXm3vxhjpUxivv0gqafnqb03wGYMN766xIuvI 3ViKy7TEe8+ndTbgtJoJX8uFleNRkPPV5JLQZunGHG68e1IS3mPS8T6peB69gGyUACMO PPIQbZPWGizGMmQ22srkeC1fij9JiZxjlidj/lx/SWToAl0YJ999/PdTSuH5c3iv49n+ ORQA== X-Forwarded-Encrypted: i=1; AJvYcCUc2D6zn4kXGA7URibDlRiJQ90b/3qlLgtNjdsm/TZcl6eW0ZgkuBf4sJcQaMymyLJ6gmcHMUPz9kIEsmA=@vger.kernel.org X-Gm-Message-State: AOJu0Yz8UhfNKSJCxDugXLWWR3+Niru/DmMaGVUBCT1JrAeLc8LmzTfq J16l77IG6B0Lk2ZqNq7eUxFsqzwX+dLfOVRTrNMWgoYZ717qDt3SxwEF X-Gm-Gg: AZuq6aIcTq2YM0OsesFVsVs3S7E7VM5QbLGQZyW4an9KGNJj1ZPXCKZUdc+V+3vcFg+ QRr5XXGNW09dS9EO5TH2p2K1uKHKlesy+142q2RvaxJymz8gkRa5vj9FgJ1+ZsEBqy3fnRgqH26 FeR3o1098K1hM86U8QlVQOtND1XPg4wJG1A1QWeNVHzuCW+qsaKSrKZNNPppTiB/+rbvynO+hDP 4gRD3mXOc2DoKGH9S5tbPfn13FGWFcdYq5qJ626LcFF50qYr4FmUenLX9fkFc50K5zYJ7mtpiY2 zBATRSdpQOmdIul2/jlQNXq9SkKbnyiNEKymeWjjSVVUgiHyBDtqWoxK6b67+QfRo0vi0mgzJzX 7ld7VRnX9AdJb3UUyD62M/n2HweUJuM0dEdAP9v8nbykVFVkKdSTWbKQnI+7EcwtsikegqztXrB RFY2ugCTBLUv+S X-Received: by 2002:a05:6102:d8a:b0:5ef:a67d:e957 with SMTP id ada2fe7eead31-5f1a53b38c0mr4505673137.17.1768890075189; Mon, 19 Jan 2026 22:21:15 -0800 (PST) Received: from [192.168.100.253] ([2800:bf0:82:11a2:7ac4:1f2:947b:2b6]) by smtp.gmail.com with ESMTPSA id ada2fe7eead31-5f1a6900c1esm4057944137.3.2026.01.19.22.21.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Jan 2026 22:21:14 -0800 (PST) From: Kurt Borja Date: Tue, 20 Jan 2026 01:20:42 -0500 Subject: [PATCH v5 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: <20260120-lock-impr-v5-2-d4d22347041f@gmail.com> References: <20260120-lock-impr-v5-0-d4d22347041f@gmail.com> In-Reply-To: <20260120-lock-impr-v5-0-d4d22347041f@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=4538; i=kuurtb@gmail.com; h=from:subject:message-id; bh=vf6b08yM9ZBa2hmugn0zaME77U5lLecJX0FGGC0bIPo=; b=owGbwMvMwCUmluBs8WX+lTTG02pJDJn5cpf5LG6/EohJOP3nqa3Td73uF36+G0KMD15gvxJ8+ csh01lbO0pZGMS4GGTFFFnaExZ9exSV99bvQOh9mDmsTCBDGLg4BWAi91MYGe5Onsm47XqjXF9l xaefDEfazxfP+84wKevVtQmG/Ptq3kxj+MM5y0bhrKqgoPmVx/JSklkXvVvOczI0r3o+ce7yRwE /WBkB 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 db803267df6e..0f8e3aa98b72 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..e263ab5eeccf 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