From nobody Sun Feb 8 14:12:48 2026 Received: from mail-ua1-f46.google.com (mail-ua1-f46.google.com [209.85.222.46]) (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 6EB073191B9 for ; Tue, 6 Jan 2026 08:07:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767686838; cv=none; b=o6FK0ZmYRO8KVNn8NpBjlHt1Lk1sL0OEaCJZBXHBkyJOk6bt832wPYnrjj/Zp3QcgqbBPpLDtUdy1FCRB1GUhWbY+aqwh6dUXHcmDHYFViJUJg1eGJm/V2NLC2sgmKyi5gSoKFyYhDYRsVwmInwien4X3q2d6EshhrcZWZu2ilY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767686838; c=relaxed/simple; bh=SDNvhXmYISbhRSNXw7cDf8FAaBgXfpTb+CF9dLnc7po=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=W3mfOpf30QGVaFCGKZCZaDL6+ji5DOwQABp2tR1rZqBVDbQwcJwne4NYLB+lMeQ/tWU7EySHXKrtqD5QuS0qLhH02G0XRbI27StIrLkOddimdI4m8WudKrmqIAgiJ0Okywhc8DMhm+S58fNrRvFkleE2LmMDSV3MKjIitW5PqE0= 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=HBRC4IUU; arc=none smtp.client-ip=209.85.222.46 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="HBRC4IUU" Received: by mail-ua1-f46.google.com with SMTP id a1e0cc1a2514c-93f5667f944so409452241.2 for ; Tue, 06 Jan 2026 00:07:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767686834; x=1768291634; 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=DWotJTEaFvNIekml25wC2h7Cy6W17ZOWtBn2DgmBWDc=; b=HBRC4IUUrrdDJht2b+PqFpoOs/BgMY/rkAXZp8PfxYRnG0Tv/C2ceAooh1G7Nb/01f lKnlehvXn+hp2Wk4TE7jzOo7ElEOWmPdIVs19p/j6PEU/2Z56wPBV2zloILZOEaPupIk hDRmYhbvE6Y/xGTMa14RBdOzLgDlW28GY4KRWXAb/MOGArxLTPJyjlitwDBQP8mpG/C2 VJHSazBoPkqpLvZwPBAAze2FHMioV8ypUwiSskRAD+ckI5NxWQRO0LESlO5+8OyzRN9N ZBeePGuFp/MAHcfbZrhabelyE4CyZ5F0Pd1wpzMPxY7ps5NkwPKZBpdboLvhCaGP2Ujg Z5SA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767686834; x=1768291634; 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=DWotJTEaFvNIekml25wC2h7Cy6W17ZOWtBn2DgmBWDc=; b=rysDkAc+5JCArN7xcqew2ku3106AzJnX66P0ff6hDml3bVTvXZuD8HH85PWlTE2wym Q3ZkGag/wuTHLhTq7Zyd6cueYD6PmJFZ6u8p9HucSOnwXrvWZu2j6zYL7cH3PGIsEst5 VjR9WTgNdEH+l3DkvSgSwtiZrTC0X/G4QjS5b3FLBCFg+vzM/WTXpRpgxhFfv6eRCYQQ OTUABur3XmqX9siOND5/swAmQu/0uy3zEix/AJgGuFve1DSlsDkT9VuONY2LHF1ibWXg /F8dZmbcDUDUytKguWbEW0SulG4cdd/xMoI+9DccxxJ/ca0rXSNj3KmJUk7xKLQ1Daa5 VV5g== X-Forwarded-Encrypted: i=1; AJvYcCUJiToj8r5prdDPaqAcSdDbCS44K8zTFvDY8GeFHt1epz/4YLMvGGs0AByNl3LZ70wiHZ+hOwc4TBRE1v8=@vger.kernel.org X-Gm-Message-State: AOJu0Ywi9zpieFlJVeeyN9+XFgH7fMd20qlRUhTl4QbcpENp+/OY9/e1 P0ZxFcQ/b//daALMQtY5gVIdPiq8rDnbj7sT8xe0TpXqxQPWZ/JguVPW X-Gm-Gg: AY/fxX72aWZJiCltTKMgXCoDfpPOeAss4CPs7Oy5FxCnVNz3uJK8lWe7A3ee5kxzogN 91YkGjB7e9+f2yRjLxWrg90P6OT7khuaCJbtdGxITZp+1R79K5sdJGaKCBiKD4cV7yyXUI7grYJ GWCnmU8sSu/eGqzBRmeCKnZGcCJO5UM/J5tjvyZu8cHzycFHeN+5u6xXJ11kUuCWfC4AzF528Br PEGGaSrOmpMyiBM9eZ55rwRvMrWfGmcVKMVmlI7pwtFMsimqiy95M8ZTclhRHkKCQk8uGpWy1ny 22hvFQq0FF4+g3414jqKsCKGFjki+iz96vEpIaRB2BvYrocvauGRDcULX6KEihgoNDegsm05MgT OvxQn8qNIJs+iSz1o7RW4EIJPy9z13L0bBVX+iIuI9nWS5hMg2NUeLO3Y2AOfNkaX5zNSsuNCsh GcAUc5D4l2cY47 X-Google-Smtp-Source: AGHT+IGdGpTqIyt6hEQbsRf4knYcrGeXLv4/KWJlDSNjEZ82/dMx8V7fOF7A+vNwmyfIMdeELVkxhg== X-Received: by 2002:a05:6102:291e:b0:5db:e851:9395 with SMTP id ada2fe7eead31-5ec74324f6dmr661509137.7.1767686834136; Tue, 06 Jan 2026 00:07:14 -0800 (PST) Received: from [192.168.100.253] ([2800:bf0:82:11a2:7ac4:1f2:947b:2b6]) by smtp.gmail.com with ESMTPSA id a1e0cc1a2514c-944124a3386sm457615241.11.2026.01.06.00.07.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jan 2026 00:07:13 -0800 (PST) From: Kurt Borja Date: Tue, 06 Jan 2026 03:06:57 -0500 Subject: [PATCH v3 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: <20260106-lock-impr-v3-2-1db909b192c0@gmail.com> References: <20260106-lock-impr-v3-0-1db909b192c0@gmail.com> In-Reply-To: <20260106-lock-impr-v3-0-1db909b192c0@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=4435; i=kuurtb@gmail.com; h=from:subject:message-id; bh=SDNvhXmYISbhRSNXw7cDf8FAaBgXfpTb+CF9dLnc7po=; b=owGbwMvMwCUmluBs8WX+lTTG02pJDJkxh1btC1q6hjGk42Uke1pnXlPVg7KrLTkBMuk3Q7Ib2 j+X5J3qKGVhEONikBVTZGlPWPTtUVTeW78Dofdh5rAygQxh4OIUgIlksTP8TzaYnGAXZF+be6jZ yFJsZl76M5nDz74/DuOy5ZuyuGp/OyPDmYz/MY8n3by1wvHTzz+SvEobm4ItvR9u3v3ZJGDHLf8 PXAA= 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. 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 34867a860a84..550d100d9cfa 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..3cf340208694 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() markings. + */ + +/** + * 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