mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Rupesh Majhi <zoone.rupert@gmail.com>
To: jic23@kernel.org
Cc: "Andy Shevchenko" <andy@kernel.org>,
	"Bill Wendling" <morbo@google.com>,
	"David Lechner" <dlechner@baylibre.com>,
	"Eddie James" <eajames@linux.ibm.com>,
	"Joel Stanley" <joel@jms.id.au>,
	"Justin Stitt" <justinstitt@google.com>,
	"Nathan Chancellor" <nathan@kernel.org>,
	"Nick Desaulniers" <ndesaulniers@google.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	llvm@lists.linux.dev
Subject: Re: [PATCH v7 09/10] iio: pressure: dps310: implement .hwfifo_flush_to_buffer()
Date: Fri, 25 Sep 2026 20:58:16 +0300	[thread overview]
Message-ID: <20260925175816.75842-1-zoone.rupert@gmail.com> (raw)
In-Reply-To: <20260922005347.069c490e@jic23-hlaptop>

On Tue, 22 Sep 2026 00:53:47 +0100
Jonathan Cameron <jic23@kernel.org> wrote:

> Adding the guard is fine - we kicked that back a while ago simply
> due to lack of users. Is there a path to annotating the non
> ACQUIRE.. functions to expose the right information to clang?

Yes, with the change below. dps310 then builds clean using
iio_device_try_claim_buffer_mode() and iio_device_release_buffer_mode(),
and clang warns on a missing or unbalanced release.

context_lock_struct() is needed because clang rejects the existing
__acquires(indio_dev) on a type that is not a lock. The header
suppression list hides that today.

diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -2252,6 +2252,7 @@ EXPORT_SYMBOL_GPL(__devm_iio_device_register);
  * iio_device_try_claim_buffer_mode() pairs or related helpers instead.
  */
 void __iio_dev_mode_lock(struct iio_dev *indio_dev)
+	__no_context_analysis
 {
 	mutex_lock(&to_iio_dev_opaque(indio_dev)->mlock);
 }
@@ -2262,6 +2263,7 @@ EXPORT_SYMBOL_GPL(__iio_dev_mode_lock);
  * @indio_dev: the iio_dev associated with the device
  */
 void __iio_dev_mode_unlock(struct iio_dev *indio_dev)
+	__no_context_analysis
 {
 	mutex_unlock(&to_iio_dev_opaque(indio_dev)->mlock);
 }
diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
--- a/include/linux/iio/iio.h
+++ b/include/linux/iio/iio.h
@@ -610,6 +610,8 @@ struct iio_buffer_setup_ops {
 				   const unsigned long *scan_mask);
 };
 
+context_lock_struct(iio_dev);
+
 /**
  * struct iio_dev - industrial I/O device
  * @modes:		[DRIVER] bitmask listing all the operating modes
@@ -726,6 +728,7 @@ void __iio_dev_mode_unlock(struct iio_dev *indio_dev) __releases(indio_dev);
  * Returns: true on success, false on failure.
  */
 static inline bool iio_device_claim_direct(struct iio_dev *indio_dev)
+	__cond_acquires(true, indio_dev)
 {
 	__iio_dev_mode_lock(indio_dev);
 
@@ -760,6 +763,7 @@ static inline bool iio_device_claim_direct(struct iio_dev *indio_dev)
  * Returns: true on success, false on failure.
  */
 static inline bool iio_device_try_claim_buffer_mode(struct iio_dev *indio_dev)
+	__cond_acquires(true, indio_dev)
 {
 	__iio_dev_mode_lock(indio_dev);
 

> I did similar for sparse and at least the direct_mode claims
> a while back. This might be a case of it just gets too complex
> though and the compiler fails to figure out what is wrong.

It holds up. drivers/iio (allmodconfig) with the analysis on for every
file goes from 254 warnings to 11, and none of the 11 are the mode lock.

If that works for you, v9 starts with this as a core patch and dps310
uses the named claim instead of a new guard.

Rupesh

  reply	other threads:[~2026-09-25 17:59 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-18 12:25 [PATCH v7 00/10] iio: pressure: dps310: FIFO and triggered buffer support Rupesh Majhi
2026-09-18 12:25 ` [PATCH v7 01/10] iio: pressure: dps310: fix CFG_REG bit definitions Rupesh Majhi
2026-09-18 12:25 ` [PATCH v7 02/10] iio: pressure: dps310: use a local device pointer in probe Rupesh Majhi
2026-09-18 12:25 ` [PATCH v7 03/10] iio: pressure: dps310: use get_unaligned_be24() for the 24-bit results Rupesh Majhi
2026-09-18 12:25 ` [PATCH v7 04/10] iio: pressure: dps310: take the lock once per raw read Rupesh Majhi
2026-09-18 12:25 ` [PATCH v7 05/10] iio: pressure: dps310: add triggered buffer support Rupesh Majhi
2026-09-18 12:25 ` [PATCH v7 06/10] iio: core: add an accessor for scan_timestamp Rupesh Majhi
2026-09-18 12:25 ` [PATCH v7 07/10] iio: pressure: dps310: read buffered samples from the hardware FIFO Rupesh Majhi
2026-09-20 18:32   ` Jonathan Cameron
2026-09-21 18:30     ` Rupesh Majhi
2026-09-18 12:25 ` [PATCH v7 08/10] iio: pressure: dps310: derive the drain interval from the watermark Rupesh Majhi
2026-09-18 12:25 ` [PATCH v7 09/10] iio: pressure: dps310: implement .hwfifo_flush_to_buffer() Rupesh Majhi
2026-09-20 18:32   ` Jonathan Cameron
2026-09-21 18:31     ` Rupesh Majhi
2026-09-21 23:53       ` Jonathan Cameron
2026-09-25 17:58         ` Rupesh Majhi [this message]
2026-09-25 18:18           ` Andy Shevchenko
2026-09-25 18:36             ` Rupesh Majhi
2026-09-18 12:25 ` [PATCH v7 10/10] iio: pressure: dps310: check the lock markings with context analysis Rupesh Majhi
2026-09-20 18:32   ` Jonathan Cameron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260925175816.75842-1-zoone.rupert@gmail.com \
    --to=zoone.rupert@gmail.com \
    --cc=andy@kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=eajames@linux.ibm.com \
    --cc=jic23@kernel.org \
    --cc=joel@jms.id.au \
    --cc=justinstitt@google.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=morbo@google.com \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=nuno.sa@analog.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®