iio: adc: qcom-spmi-adc5-gen3: fix lock annotations on mutex helpers
Subsystems (2)
PATCH v2 1/1 iio: adc: qcom-spmi-adc5-gen3: fix lock annotations on mutex helpers
Since commit 5b63d0ae94cc ("compiler-context-analysis: Remove Sparse support"), __acquires() and __releases() only feed context analysis. Their argument is parsed before the function body, where only dev is in scope, so with analysis enabled for this file the build fails:
error: use of undeclared identifier 'adc'
These helpers take and drop the lock for the ADC_TM driver, which only sees their declarations in the header. Naming the lock there would mean exposing struct adc5_chip, and with no annotation at all the analysis flags the unbalanced locking. Mark both __context_unsafe().
---
v2: explain __context_unsafe() in commit message (Andy)
v1: https://lore.kernel.org/linux-iio/[email protected]/
Found by building with CONTEXT_ANALYSIS_qcom-spmi-adc5-gen3.o=y, which the driver does not set today. Build tested only, no hardware here.
drivers/iio/adc/qcom-spmi-adc5-gen3.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/adc/qcom-spmi-adc5-gen3.c +2 -2
@@ -663,7 +663,7 @@ static int adc5_gen3_add_aux_tm_device(struct adc5_chip *adc) }void adc5_gen3_mutex_lock (struct device *dev) - __acquires(&adc->lock) +__context_unsafe (/* returns with adc->lock held */ ) {struct iio_dev *indio_dev =dev_get_drvdata (dev->parent);struct adc5_chip *adc =iio_priv (indio_dev);
@@ -673,7 +673,7 @@ void adc5_gen3_mutex_lock(struct device *dev)EXPORT_SYMBOL_NS_GPL (adc5_gen3_mutex_lock,"QCOM_SPMI_ADC5_GEN3" );void adc5_gen3_mutex_unlock (struct device *dev) - __releases(&adc->lock) +__context_unsafe (/* releases adc->lock */ ) {struct iio_dev *indio_dev =dev_get_drvdata (dev->parent);struct adc5_chip *adc =iio_priv (indio_dev);
base-commit: 43ffda3c7f8456bbe641ae8249a077a361b97880
Signature · 1 line
2.43.0
Quoted 12 lines · Rupesh Majhi
Since commit
5b63d0ae94cc("compiler-context-analysis: Remove Sparse support"),__acquires()and__releases()only feed context analysis. Their argument is parsed before the function body, where only dev is in scope, so with analysis enabled for this file the build fails:error: use of undeclared identifier 'adc'
These helpers take and drop the lock for the
ADC_TMdriver, which only sees their declarations in the header. Naming the lock there would mean exposing structadc5_chip, and with no annotation at all the analysis flags the unbalanced locking. Mark both__context_unsafe().
Quoted 4 lines
Fixes baff45179e90 ("iio: adc: Add support for QCOM PMIC5 Gen3 ADC")Cc Marco Elver <[email protected]>Cc Bart Van Assche <[email protected]>
Move Cc list after the '---' line (similar to the changelog block below), it will have the same effect on email headers, but won't pollute the commit message.
Quoted 1 line
Assisted-by LLM
As of today we killed that tag, drop it.
Quoted 7 lines
Signed-off-by Rupesh Majhi <[email protected]>---
v2: explain__context_unsafe()in commit message (Andy)
v1: https://lore.kernel.org/linux-iio/[email protected]/Found by building with CONTEXT_ANALYSIS_qcom-spmi-adc5-gen3.o=y, which the driver does not set today. Build tested only, no hardware here.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 2 lines · Rupesh Majhi
Found by building with CONTEXT_ANALYSIS_qcom-spmi-adc5-gen3.o=y, which the driver does not set today. Build tested only, no hardware here.
Why doesn't this patch set CONTEXT_ANALYSIS_qcom-spmi-adc5-gen3.o=y? Shouldn't that change be included in this patch?
Thanks,
Bart.
Quoted 2 lines · Bart Van Assche
Why doesn't this patch set CONTEXT_ANALYSIS_qcom-spmi-adc5-gen3.o=y? Shouldn't that change be included in this patch?
Fair point, without it nothing checks these annotations. v3 will enable it as a separate patch, so the fix can still be backported on its own.
Jonathan Cameron
maintainerQuoted 6 lines · On Wed, 21 Oct 2026 21:19:44 +0300 Rupesh Majhi <[email protected]> wrote:
Quoted 2 lines · Bart Van Assche
Why doesn't this patch set CONTEXT_ANALYSIS_qcom-spmi-adc5-gen3.o=y? Shouldn't that change be included in this patch?
Fair point, without it nothing checks these annotations. v3 will enable it as a separate patch, so the fix can still be backported on its own.
I think it's unlikely an generic subsystem wide (or broader) enablement of this will get back ported, so instead let us treat this as a forwards looking move.
Drop the fixes tag and perhaps include a second patch enabling the context analysis much more broadly.
I haven't tried yet, but I think you said not much broke?
Jonathan
Quoted 1 line · Jonathan Cameron
I haven't tried yet, but I think you said not much broke?
I hadn't tried either, so I did: CONTEXT_ANALYSIS := y in every drivers/iio Makefile, on testing, x86_64 allmodconfig, clang 23. 255 warnings.
240 come from iio_device_claim_direct() and iio_device_try_claim_buffer_mode() lacking __cond_acquires(). The rest are 4 in industrialio-core.c and 11 in five drivers, none of them real bugs. With those annotated it builds clean.
v3 would be this fix without Fixes tag, core annotations, one patch per driver, then enabling it for drivers/iio. Does that work for you?
Jonathan Cameron
maintainerQuoted 7 lines · On Fri, 23 Oct 2026 09:47:09 +0300 Rupesh Majhi <[email protected]> wrote:
Quoted 1 line · Jonathan Cameron
I haven't tried yet, but I think you said not much broke?
I hadn't tried either, so I did:
CONTEXT_ANALYSIS:= y in everydrivers/iioMakefile, on testing,x86_64allmodconfig, clang 23. 255 warnings.
Quoted 7 lines
240 come from
iio_device_claim_direct()andiio_device_try_claim_buffer_mode()lacking__cond_acquires(). The rest are 4 inindustrialio-core.cand 11 in five drivers, none of them real bugs. With those annotated it builds clean.v3 would be this fix without Fixes tag, core annotations, one patch per driver, then enabling it for
drivers/iio. Does that work for you?
Yes, though no need to necessarily do it in one go if you prefer smaller steps. I don't mind merging fixes like this without the global enable. Maybe can do it on a directory first?
J