iio: adc: qcom-spmi-adc5-gen3: fix lock annotations on mutex helpers
Subsystems (2)
PATCH 1/1 iio: adc: qcom-spmi-adc5-gen3: fix lock annotations on mutex helpers
The __acquires() and __releases() on adc5_gen3_mutex_lock() and adc5_gen3_mutex_unlock() name adc, a local declared in the body. With context analysis enabled for this file, the build fails:
error: use of undeclared identifier 'adc'
The lock and unlock are split across these two helpers for the ADC_TM driver, so mark them __context_unsafe() instead.
---
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: 04434a1d0f311d76b1f15fa987918b471a0b8c6a
Signature · 1 line
2.43.0
Quoted 8 lines · Rupesh Majhi
The
__acquires()and__releases()onadc5_gen3_mutex_lock()andadc5_gen3_mutex_unlock()name adc, a local declared in the body. With context analysis enabled for this file, the build fails:error: use of undeclared identifier 'adc'
The lock and unlock are split across these two helpers for the
ADC_TMdriver, so mark them__context_unsafe()instead.
Doesn't sound right to me. The __acquires() and __releases() IIRC are sparse annotations. If clang has something special, it needs to be addressed in the compiler-clang.h, no?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 5 lines · Andy Shevchenko
Quoted 4 lines · Rupesh Majhi
The
__acquires()and__releases()onadc5_gen3_mutex_lock()andadc5_gen3_mutex_unlock()name adc, a local declared in the body. With context analysis enabled for this file, the build fails:
Quoted 8 lines
Quoted 4 lines
error: use of undeclared identifier 'adc'
The lock and unlock are split across these two helpers for the
ADC_TMdriver, so mark them__context_unsafe()instead.Doesn't sound right to me. The
__acquires()and__releases()IIRC are sparse annotations. If clang has something special, it needs to be addressed in thecompiler-clang.h, no?
Sparse support for them went away in v7.0 with 5b63d0ae94cc ("compiler-context-analysis: Remove Sparse support"). They are now defined in compiler-context-analysis.h and expand to clang's acquire_capability() and release_capability(), or to nothing.
The argument is parsed at the declaration, where only dev is in scope, so no header change can make adc visible there.
Sorry for the slow reply.
Quoted 15 lines · Rupesh Majhi
Quoted 5 lines · Andy Shevchenko
Quoted 4 lines · Rupesh Majhi
The
__acquires()and__releases()onadc5_gen3_mutex_lock()andadc5_gen3_mutex_unlock()name adc, a local declared in the body. With context analysis enabled for this file, the build fails:Quoted 8 lines
Quoted 4 lines
error: use of undeclared identifier 'adc'
The lock and unlock are split across these two helpers for the
ADC_TMdriver, so mark them__context_unsafe()instead.Doesn't sound right to me. The
__acquires()and__releases()IIRC are sparse annotations. If clang has something special, it needs to be addressed in thecompiler-clang.h, no?
Quoted 7 lines
Sparse support for them went away in v7.0 with
5b63d0ae94cc("compiler-context-analysis: Remove Sparse support"). They are now defined incompiler-context-analysis.hand expand to clang'sacquire_capability()andrelease_capability(), or to nothing.The argument is parsed at the declaration, where only dev is in scope, so no header change can make adc visible there.
You need to summarise that in the commit message.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Jonathan Cameron
maintainerQuoted 5 lines · On Sun, 4 Oct 2026 11:42:56 +0300 Andy Shevchenko…
Quoted 4 lines · Rupesh Majhi
The
__acquires()and__releases()onadc5_gen3_mutex_lock()andadc5_gen3_mutex_unlock()name adc, a local declared in the body. With context analysis enabled for this file, the build fails:
Quoted 9 lines
Quoted 4 lines
error: use of undeclared identifier 'adc'
The lock and unlock are split across these two helpers for the
ADC_TMdriver, so mark them__context_unsafe()instead.Doesn't sound right to me. The
__acquires()and__releases()IIRC are sparse annotations. If clang has something special, it needs to be addressed in thecompiler-clang.h, no?
It's in compiler-context-analysis.h and for now I believe is clang only. Reuses the older sparse definitions. I think the intent is to avoid churn.
I currently have no idea if this is the right fix. The only users today are places where a lock is intentionally skipped.
+CC Marco and Bart and putting back the patch content for context.
Quoted 26 lines
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:
04434a1d0f311d76b1f15fa987918b471a0b8c6aSignature · 1 line
2.43.0
Quoted 43 lines · Jonathan Cameron
Quoted 5 lines · On Sun, 4 Oct 2026 11:42:56 +0300 Andy Shevchenko…
Quoted 4 lines · Rupesh Majhi
The
__acquires()and__releases()onadc5_gen3_mutex_lock()andadc5_gen3_mutex_unlock()name adc, a local declared in the body. With context analysis enabled for this file, the build fails:Quoted 9 lines
Quoted 4 lines
error: use of undeclared identifier 'adc'
The lock and unlock are split across these two helpers for the
ADC_TMdriver, so mark them__context_unsafe()instead.Doesn't sound right to me. The
__acquires()and__releases()IIRC are sparse annotations. If clang has something special, it needs to be addressed in thecompiler-clang.h, no?It's in
compiler-context-analysis.hand for now I believe is clang only. Reuses the older sparse definitions. I think the intent is to avoid churn.I currently have no idea if this is the right fix. The only users today are places where a lock is intentionally skipped.
+CC Marco and Bart and putting back the patch content for context.
Quoted 16 lines
drivers/iio/adc/qcom-spmi-adc5-gen3.c +1
-1@@ -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" );
Quoted 6 lines
drivers/iio/adc/qcom-spmi-adc5-gen3.c void adc5_gen3_mutex_lock(struct device *dev) · line 679
Quoted 6 lines
drivers/iio/adc/qcom-spmi-adc5-gen3.c +1
-1void 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);
You could probably stick the whole iio_priv(dev_get_drvdata(dev->parent)) expression into a helper get_adc5_chip(...), and then __acquires/__releases(&get_adc5_chip(dev)->lock) should work. But that's only worth it if the declarations get the annotations, because if only the definitions have the annotation, any calls outside this particular TU ignore the annotations anyway, so __context_unsafe is reasonable if you don't want to do a larger change.