[PATCH v4 2/9] iio: core: annotate the conditional mode claims

From: Rupesh Majhi

Date: Tue Oct 27 2026 - 08:54:11 EST


iio_device_claim_direct() and iio_device_try_claim_buffer_mode() hold
the mode lock only when they return true, but carry no annotation. With
context analysis on, each caller that releases the claim is reported
for releasing a lock it never took.

Mark both __cond_acquires(true, indio_dev), the token that
__iio_dev_mode_lock() acquires. Sparse no longer reads these
annotations, so drop the comment about it.

Signed-off-by: Rupesh Majhi <zoone.rupert@xxxxxxxxx>
---
Cc: Marco Elver <elver@xxxxxxxxxx>
Cc: Bart Van Assche <bvanassche@xxxxxxx>

include/linux/iio/iio.h | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
index 9b63785d5aec..ca91f5a64626 100644
--- a/include/linux/iio/iio.h
+++ b/include/linux/iio/iio.h
@@ -707,13 +707,6 @@ int iio_push_event(struct iio_dev *indio_dev, u64 ev_code, s64 timestamp);
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);

-/*
- * 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 __acquires() and __releases() annotations.
- */
-
/**
* iio_device_claim_direct() - Keep device in direct mode
* @indio_dev: the iio_dev associated with the device
@@ -726,6 +719,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 +754,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);

--
2.43.0