Linux IIO development
 help / color / mirror / Atom feed
* [PATCH] iio: adc: ad7280a: handle spi_setup() errors in probe()
@ 2025-11-14 15:13 Pavel Zhigulin
  2025-11-14 16:27 ` Marcelo Schmitt
  0 siblings, 1 reply; 3+ messages in thread
From: Pavel Zhigulin @ 2025-11-14 15:13 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: Pavel Zhigulin, Michael Hennerich, Jonathan Cameron,
	David Lechner, Nuno Sá, Andy Shevchenko, Greg Kroah-Hartman,
	linux-iio, linux-kernel, lvc-project

The probe() function ignored the return value of spi_setup(), leaving SPI
configuration failures undetected. If spi_setup() fails, the driver should
stop initialization and propagate the error to the caller.

Add proper error handling: check the return value of spi_setup() and return
it on failure.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: 2051f25d2a26 ("iio: adc: New driver for AD7280A Lithium Ion Battery Monitoring System")
Signed-off-by: Pavel Zhigulin <Pavel.Zhigulin@kaspersky.com>
---
 drivers/iio/adc/ad7280a.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/adc/ad7280a.c b/drivers/iio/adc/ad7280a.c
index dda2986ccda0..63fceb239bd8 100644
--- a/drivers/iio/adc/ad7280a.c
+++ b/drivers/iio/adc/ad7280a.c
@@ -1024,7 +1024,9 @@ static int ad7280_probe(struct spi_device *spi)

 	st->spi->max_speed_hz = AD7280A_MAX_SPI_CLK_HZ;
 	st->spi->mode = SPI_MODE_1;
-	spi_setup(st->spi);
+	ret = spi_setup(st->spi);
+	if (ret < 0)
+		return ret;

 	st->ctrl_lb = FIELD_PREP(AD7280A_CTRL_LB_ACQ_TIME_MSK, st->acquisition_time) |
 		FIELD_PREP(AD7280A_CTRL_LB_THERMISTOR_MSK, st->thermistor_term_en);
--
2.43.0


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

* Re: [PATCH] iio: adc: ad7280a: handle spi_setup() errors in probe()
  2025-11-14 15:13 [PATCH] iio: adc: ad7280a: handle spi_setup() errors in probe() Pavel Zhigulin
@ 2025-11-14 16:27 ` Marcelo Schmitt
  2025-11-15 17:14   ` Jonathan Cameron
  0 siblings, 1 reply; 3+ messages in thread
From: Marcelo Schmitt @ 2025-11-14 16:27 UTC (permalink / raw)
  To: Pavel Zhigulin
  Cc: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
	David Lechner, Nuno Sá, Andy Shevchenko, Greg Kroah-Hartman,
	linux-iio, linux-kernel, lvc-project

On 11/14, Pavel Zhigulin wrote:
> The probe() function ignored the return value of spi_setup(), leaving SPI
> configuration failures undetected. If spi_setup() fails, the driver should
> stop initialization and propagate the error to the caller.
> 
> Add proper error handling: check the return value of spi_setup() and return
> it on failure.
> 
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
> 
> Fixes: 2051f25d2a26 ("iio: adc: New driver for AD7280A Lithium Ion Battery Monitoring System")
> Signed-off-by: Pavel Zhigulin <Pavel.Zhigulin@kaspersky.com>

Reviewed-by: Marcelo Schmitt <marcelo.schmitt@analog.com>

As patch suggestion, we could also have
  spi-cpha: true
in ad7280a dt-binding.

Thanks,
Marcelo

> ---
>  drivers/iio/adc/ad7280a.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/adc/ad7280a.c b/drivers/iio/adc/ad7280a.c
> index dda2986ccda0..63fceb239bd8 100644
> --- a/drivers/iio/adc/ad7280a.c
> +++ b/drivers/iio/adc/ad7280a.c
> @@ -1024,7 +1024,9 @@ static int ad7280_probe(struct spi_device *spi)
> 
>  	st->spi->max_speed_hz = AD7280A_MAX_SPI_CLK_HZ;
>  	st->spi->mode = SPI_MODE_1;
> -	spi_setup(st->spi);
> +	ret = spi_setup(st->spi);
> +	if (ret < 0)
> +		return ret;
> 
>  	st->ctrl_lb = FIELD_PREP(AD7280A_CTRL_LB_ACQ_TIME_MSK, st->acquisition_time) |
>  		FIELD_PREP(AD7280A_CTRL_LB_THERMISTOR_MSK, st->thermistor_term_en);
> --
> 2.43.0
> 
> 

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

* Re: [PATCH] iio: adc: ad7280a: handle spi_setup() errors in probe()
  2025-11-14 16:27 ` Marcelo Schmitt
@ 2025-11-15 17:14   ` Jonathan Cameron
  0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2025-11-15 17:14 UTC (permalink / raw)
  To: Marcelo Schmitt
  Cc: Pavel Zhigulin, Lars-Peter Clausen, Michael Hennerich,
	David Lechner, Nuno Sá, Andy Shevchenko, Greg Kroah-Hartman,
	linux-iio, linux-kernel, lvc-project

On Fri, 14 Nov 2025 13:27:04 -0300
Marcelo Schmitt <marcelo.schmitt1@gmail.com> wrote:

> On 11/14, Pavel Zhigulin wrote:
> > The probe() function ignored the return value of spi_setup(), leaving SPI
> > configuration failures undetected. If spi_setup() fails, the driver should
> > stop initialization and propagate the error to the caller.
> > 
> > Add proper error handling: check the return value of spi_setup() and return
> > it on failure.
> > 
> > Found by Linux Verification Center (linuxtesting.org) with SVACE.
> > 
> > Fixes: 2051f25d2a26 ("iio: adc: New driver for AD7280A Lithium Ion Battery Monitoring System")
> > Signed-off-by: Pavel Zhigulin <Pavel.Zhigulin@kaspersky.com>  
> 
> Reviewed-by: Marcelo Schmitt <marcelo.schmitt@analog.com>
> 
> As patch suggestion, we could also have
>   spi-cpha: true
> in ad7280a dt-binding.
That would make sense as a follow up.

Applied this to the fixes-togreg branch of iio.git. Given point in cycle
this may well wait until the merge window.

Thanks,

Jonathan

> 
> Thanks,
> Marcelo
> 
> > ---
> >  drivers/iio/adc/ad7280a.c | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/iio/adc/ad7280a.c b/drivers/iio/adc/ad7280a.c
> > index dda2986ccda0..63fceb239bd8 100644
> > --- a/drivers/iio/adc/ad7280a.c
> > +++ b/drivers/iio/adc/ad7280a.c
> > @@ -1024,7 +1024,9 @@ static int ad7280_probe(struct spi_device *spi)
> > 
> >  	st->spi->max_speed_hz = AD7280A_MAX_SPI_CLK_HZ;
> >  	st->spi->mode = SPI_MODE_1;
> > -	spi_setup(st->spi);
> > +	ret = spi_setup(st->spi);
> > +	if (ret < 0)
> > +		return ret;
> > 
> >  	st->ctrl_lb = FIELD_PREP(AD7280A_CTRL_LB_ACQ_TIME_MSK, st->acquisition_time) |
> >  		FIELD_PREP(AD7280A_CTRL_LB_THERMISTOR_MSK, st->thermistor_term_en);
> > --
> > 2.43.0
> > 
> >   
> 


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

end of thread, other threads:[~2025-11-15 17:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-14 15:13 [PATCH] iio: adc: ad7280a: handle spi_setup() errors in probe() Pavel Zhigulin
2025-11-14 16:27 ` Marcelo Schmitt
2025-11-15 17:14   ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox