mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3] iio: adc: qcom-spmi-adc5-gen3: fix lock annotations on mutex helpers
@ 2026-10-25 19:15 Rupesh Majhi
  2026-10-25 20:10 ` Bart Van Assche
  0 siblings, 1 reply; 5+ messages in thread
From: Rupesh Majhi @ 2026-10-25 19:15 UTC (permalink / raw)
  To: Andy Shevchenko, David Lechner, Jonathan Cameron, Nuno Sá
  Cc: linux-arm-msm, linux-iio, linux-kernel, Rupesh Majhi,
	Marco Elver, Bart Van Assche, Jishnu Prakash

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().

Signed-off-by: Rupesh Majhi <zoone.rupert@gmail.com>
---
Cc: Marco Elver <elver@google.com>
Cc: Bart Van Assche <bvanassche@acm.org>
Cc: Jishnu Prakash <jishnu.prakash@oss.qualcomm.com>

v3: drop Fixes tag (Jonathan), trailer cleanup (Andy)
v2: __context_unsafe() explained in commit message (Andy)
    https://lore.kernel.org/linux-iio/20261021052435.112686-1-zoone.rupert@gmail.com/
v1: https://lore.kernel.org/linux-iio/20261003214516.128573-1-zoone.rupert@gmail.com/

Found by building with CONTEXT_ANALYSIS_qcom-spmi-adc5-gen3.o=y, which the
driver does not set today. Enabling it comes later, with the IIO core
annotations. Build tested only, no hardware here. Patch and commit
message drafted with an LLM coding assistant.

 drivers/iio/adc/qcom-spmi-adc5-gen3.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/adc/qcom-spmi-adc5-gen3.c b/drivers/iio/adc/qcom-spmi-adc5-gen3.c
index c68c6c5f6aca..6a3cabedf4e8 100644
--- a/drivers/iio/adc/qcom-spmi-adc5-gen3.c
+++ b/drivers/iio/adc/qcom-spmi-adc5-gen3.c
@@ -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: c9dbe2a47f635465c9985b7af74d2ae310e98125
-- 
2.43.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v3] iio: adc: qcom-spmi-adc5-gen3: fix lock annotations on mutex helpers
  2026-10-25 19:15 [PATCH v3] iio: adc: qcom-spmi-adc5-gen3: fix lock annotations on mutex helpers Rupesh Majhi
@ 2026-10-25 20:10 ` Bart Van Assche
  2026-10-25 21:59   ` Jonathan Cameron
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Van Assche @ 2026-10-25 20:10 UTC (permalink / raw)
  To: Rupesh Majhi, Andy Shevchenko, David Lechner, Jonathan Cameron,
	Nuno Sá
  Cc: linux-arm-msm, linux-iio, linux-kernel, Marco Elver, Jishnu Prakash

On 10/25/26 12:15 PM, Rupesh Majhi wrote:
> Found by building with CONTEXT_ANALYSIS_qcom-spmi-adc5-gen3.o=y

Please include the CONTEXT_ANALYSIS_qcom-spmi-adc5-gen3.o=y change in
your patch.

> diff --git a/drivers/iio/adc/qcom-spmi-adc5-gen3.c b/drivers/iio/adc/qcom-spmi-adc5-gen3.c
> index c68c6c5f6aca..6a3cabedf4e8 100644
> --- a/drivers/iio/adc/qcom-spmi-adc5-gen3.c
> +++ b/drivers/iio/adc/qcom-spmi-adc5-gen3.c
> @@ -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: c9dbe2a47f635465c9985b7af74d2ae310e98125

Please consider replacing the above with the patch below:

diff --git a/drivers/iio/adc/qcom-spmi-adc5-gen3.c 
b/drivers/iio/adc/qcom-spmi-adc5-gen3.c
index c68c6c5f6aca..09013c6e44a0 100644
--- a/drivers/iio/adc/qcom-spmi-adc5-gen3.c
+++ b/drivers/iio/adc/qcom-spmi-adc5-gen3.c
@@ -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)
+       __acquires(&((struct adc5_chip 
*)iio_priv(dev_get_drvdata(dev->parent)))->lock)
  {
         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)
+       __releases(&((struct adc5_chip 
*)iio_priv(dev_get_drvdata(dev->parent)))->lock)
  {
         struct iio_dev *indio_dev = dev_get_drvdata(dev->parent);
         struct adc5_chip *adc = iio_priv(indio_dev);

Thanks,

Bart.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v3] iio: adc: qcom-spmi-adc5-gen3: fix lock annotations on mutex helpers
  2026-10-25 20:10 ` Bart Van Assche
@ 2026-10-25 21:59   ` Jonathan Cameron
  2026-10-26  0:27     ` Bart Van Assche
  2026-10-26  8:13     ` Rupesh Majhi
  0 siblings, 2 replies; 5+ messages in thread
From: Jonathan Cameron @ 2026-10-25 21:59 UTC (permalink / raw)
  To: Bart Van Assche
  Cc: Rupesh Majhi, Andy Shevchenko, David Lechner, Nuno Sá,
	linux-arm-msm, linux-iio, linux-kernel, Marco Elver,
	Jishnu Prakash

On Sun, 25 Oct 2026 13:10:26 -0700
Bart Van Assche <bvanassche@acm.org> wrote:

> On 10/25/26 12:15 PM, Rupesh Majhi wrote:
> > Found by building with CONTEXT_ANALYSIS_qcom-spmi-adc5-gen3.o=y  
> 
> Please include the CONTEXT_ANALYSIS_qcom-spmi-adc5-gen3.o=y change in
> your patch.
> 

I asked that we didn't do this because intent is to follow with
remaining fixes to be able to enable this IIO tree wide.
I'd rather avoid the churn of piecewise makefile updates if
we are going to be there soon.

Rupesh, if you think that is coming soon then please just make
next version of this the first patch in that series.

If not I don't mind merging this sooner with the makefile change
to ensure this gets used in the meantime.

Thanks,

Jonathan

> > diff --git a/drivers/iio/adc/qcom-spmi-adc5-gen3.c b/drivers/iio/adc/qcom-spmi-adc5-gen3.c
> > index c68c6c5f6aca..6a3cabedf4e8 100644
> > --- a/drivers/iio/adc/qcom-spmi-adc5-gen3.c
> > +++ b/drivers/iio/adc/qcom-spmi-adc5-gen3.c
> > @@ -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: c9dbe2a47f635465c9985b7af74d2ae310e98125  
> 
> Please consider replacing the above with the patch below:
> 
> diff --git a/drivers/iio/adc/qcom-spmi-adc5-gen3.c 
> b/drivers/iio/adc/qcom-spmi-adc5-gen3.c
> index c68c6c5f6aca..09013c6e44a0 100644
> --- a/drivers/iio/adc/qcom-spmi-adc5-gen3.c
> +++ b/drivers/iio/adc/qcom-spmi-adc5-gen3.c
> @@ -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)
> +       __acquires(&((struct adc5_chip 
> *)iio_priv(dev_get_drvdata(dev->parent)))->lock)
>   {
>          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)
> +       __releases(&((struct adc5_chip 
> *)iio_priv(dev_get_drvdata(dev->parent)))->lock)
>   {
>          struct iio_dev *indio_dev = dev_get_drvdata(dev->parent);
>          struct adc5_chip *adc = iio_priv(indio_dev);
> 
> Thanks,
> 
> Bart.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v3] iio: adc: qcom-spmi-adc5-gen3: fix lock annotations on mutex helpers
  2026-10-25 21:59   ` Jonathan Cameron
@ 2026-10-26  0:27     ` Bart Van Assche
  2026-10-26  8:13     ` Rupesh Majhi
  1 sibling, 0 replies; 5+ messages in thread
From: Bart Van Assche @ 2026-10-26  0:27 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Rupesh Majhi, Andy Shevchenko, David Lechner, Nuno Sá,
	linux-arm-msm, linux-iio, linux-kernel, Marco Elver,
	Jishnu Prakash

On 10/25/26 2:59 PM, Jonathan Cameron wrote:
> I asked that we didn't do this because intent is to follow with
> remaining fixes to be able to enable this IIO tree wide.
> I'd rather avoid the churn of piecewise makefile updates if
> we are going to be there soon.
> 
> Rupesh, if you think that is coming soon then please just make
> next version of this the first patch in that series.
> 
> If not I don't mind merging this sooner with the makefile change
> to ensure this gets used in the meantime.

As maintainer it is of course your call how to proceed.

In case anyone would be interested in working on a patch series that
annotates all IIO drivers at once, feel free to borrow annotations from
this kernel branch (entirely untested):
https://github.com/bvanassche/linux/tree/thread-safety

That branch has lock context annotations for all drivers in the entire
kernel tree. I'm sending the code from that branch upstream in small
chunks as time permits.

Thanks,

Bart.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v3] iio: adc: qcom-spmi-adc5-gen3: fix lock annotations on mutex helpers
  2026-10-25 21:59   ` Jonathan Cameron
  2026-10-26  0:27     ` Bart Van Assche
@ 2026-10-26  8:13     ` Rupesh Majhi
  1 sibling, 0 replies; 5+ messages in thread
From: Rupesh Majhi @ 2026-10-26  8:13 UTC (permalink / raw)
  To: jic, Jonathan Cameron
  Cc: Bart Van Assche, Andy Shevchenko, David Lechner, Jishnu Prakash,
	Nuno Sá,
	Marco Elver, linux-arm-msm, linux-iio, linux-kernel

On Sun, Oct 25, 2026 at 09:59:54PM +0000, Jonathan Cameron wrote:
> Rupesh, if you think that is coming soon then please just make
> next version of this the first patch in that series.

It is close. The other fixes are done and build clean, and most of them
match Bart's branch. I'll send them as one series with this as the first
patch.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-10-26  8:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-25 19:15 [PATCH v3] iio: adc: qcom-spmi-adc5-gen3: fix lock annotations on mutex helpers Rupesh Majhi
2026-10-25 20:10 ` Bart Van Assche
2026-10-25 21:59   ` Jonathan Cameron
2026-10-26  0:27     ` Bart Van Assche
2026-10-26  8:13     ` Rupesh Majhi

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®