[PATCH] iio: sca3000: Fix a resource leak in sca3000_probe()

Harshit Mogalapalli posted 1 patch 1 week, 2 days ago
drivers/iio/accel/sca3000.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
[PATCH] iio: sca3000: Fix a resource leak in sca3000_probe()
Posted by Harshit Mogalapalli 1 week, 2 days ago
spi->irq from request_threaded_irq() not released when
iio_device_register() fails. Add an return value check and jump to a
common error handler when iio_device_register() fails.

Fixes: 9a4936dc89a3 ("staging:iio:accel:sca3000 Tidy up probe order to avoid a race.")
Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
---
 drivers/iio/accel/sca3000.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/accel/sca3000.c b/drivers/iio/accel/sca3000.c
index bfa8a3f5a92f..9ef4d6e27466 100644
--- a/drivers/iio/accel/sca3000.c
+++ b/drivers/iio/accel/sca3000.c
@@ -1489,7 +1489,11 @@ static int sca3000_probe(struct spi_device *spi)
 	if (ret)
 		goto error_free_irq;
 
-	return iio_device_register(indio_dev);
+	ret = iio_device_register(indio_dev);
+	if (ret)
+		goto error_free_irq;
+
+	return 0;
 
 error_free_irq:
 	if (spi->irq)
-- 
2.47.3
Re: [PATCH] iio: sca3000: Fix a resource leak in sca3000_probe()
Posted by Andy Shevchenko 1 week, 2 days ago
On Tue, Jan 27, 2026 at 10:49:49PM -0800, Harshit Mogalapalli wrote:
> spi->irq from request_threaded_irq() not released when
> iio_device_register() fails. Add an return value check and jump to a
> common error handler when iio_device_register() fails.

LGTM, but I would rather converting this to use managed resources.

So, if Jonathan wants to take this first,
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH] iio: sca3000: Fix a resource leak in sca3000_probe()
Posted by Harshit Mogalapalli 1 week, 2 days ago
Hi Andy,

On 28/01/26 15:18, Andy Shevchenko wrote:
> On Tue, Jan 27, 2026 at 10:49:49PM -0800, Harshit Mogalapalli wrote:
>> spi->irq from request_threaded_irq() not released when
>> iio_device_register() fails. Add an return value check and jump to a
>> common error handler when iio_device_register() fails.
> 
> LGTM, but I would rather converting this to use managed resources.
> 

Thanks for the review.

I’ll follow up with a separate patch that converts it to devm-based
resource handling. Maybe that helps in a way to keep the fix and
refactor separate ?

> So, if Jonathan wants to take this first,
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
>

Thanks!

Regards,
Harshit


Re: [PATCH] iio: sca3000: Fix a resource leak in sca3000_probe()
Posted by Jonathan Cameron 1 week, 1 day ago
On Wed, 28 Jan 2026 20:15:06 +0530
Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com> wrote:

> Hi Andy,
> 
> On 28/01/26 15:18, Andy Shevchenko wrote:
> > On Tue, Jan 27, 2026 at 10:49:49PM -0800, Harshit Mogalapalli wrote:  
> >> spi->irq from request_threaded_irq() not released when
> >> iio_device_register() fails. Add an return value check and jump to a
> >> common error handler when iio_device_register() fails.  
> > 
> > LGTM, but I would rather converting this to use managed resources.
> >   
> 
> Thanks for the review.
> 
> I’ll follow up with a separate patch that converts it to devm-based
> resource handling. Maybe that helps in a way to keep the fix and
> refactor separate ?
> 
Yes.

> > So, if Jonathan wants to take this first,
> > Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
> >  
Applied.

Not that often we get changes for this one. It was one of the
earliest IIO drivers. Anyhow, nothing wrong with modernising it
if you want to work on it!

Thanks,

Jonathan

> 
> Thanks!
> 
> Regards,
> Harshit
> 
> 
Re: [PATCH] iio: sca3000: Fix a resource leak in sca3000_probe()
Posted by Harshit Mogalapalli 1 week, 2 days ago
Hi,
On 28/01/26 12:19, Harshit Mogalapalli wrote:
> spi->irq from request_threaded_irq() not released when
> iio_device_register() fails. Add an return value check and jump to a
> common error handler when iio_device_register() fails.
> 
> Fixes: 9a4936dc89a3 ("staging:iio:accel:sca3000 Tidy up probe order to avoid a race.")
> Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
> ---

Missed informing about how it was found.

Only compile tested, found with smatch.

>   drivers/iio/accel/sca3000.c | 6 +++++-
>   1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/accel/sca3000.c b/drivers/iio/accel/sca3000.c
> index bfa8a3f5a92f..9ef4d6e27466 100644
> --- a/drivers/iio/accel/sca3000.c
> +++ b/drivers/iio/accel/sca3000.c
> @@ -1489,7 +1489,11 @@ static int sca3000_probe(struct spi_device *spi)
>   	if (ret)
>   		goto error_free_irq;
>   
> -	return iio_device_register(indio_dev);
> +	ret = iio_device_register(indio_dev);
> +	if (ret)
> +		goto error_free_irq;
> +
> +	return 0;
>   
>   error_free_irq:
>   	if (spi->irq)