[PATCH v2 2/4] iio: gyro: mpu3050: Fix irq resource leak

Ethan Tidmore posted 4 patches 1 month, 1 week ago
[PATCH v2 2/4] iio: gyro: mpu3050: Fix irq resource leak
Posted by Ethan Tidmore 1 month, 1 week ago
The interrupt handler is setup but only a few lines down if
iio_trigger_register() fails the function returns without properly
releasing the handler:

        ret = request_threaded_irq(irq,
                                   mpu3050_irq_handler,
                                   mpu3050_irq_thread,
                                   irq_trig,
                                   mpu3050->trig->name,
                                   mpu3050->trig);

...

        ret = iio_trigger_register(mpu3050->trig);
        if (ret)
                return ret;

        indio_dev->trig = iio_trigger_get(mpu3050->trig);

        return 0;
}

Add cleanup goto to resolve resource leak.

Detected by Smatch:
drivers/iio/gyro/mpu3050-core.c:1128 mpu3050_trigger_probe() warn:
'irq' from request_threaded_irq() not released on lines: 1124.

Fixes: 3904b28efb2c7 ("iio: gyro: Add driver for the MPU-3050 gyroscope")
Signed-off-by: Ethan Tidmore <ethantidmore06@gmail.com>
---
 drivers/iio/gyro/mpu3050-core.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/gyro/mpu3050-core.c b/drivers/iio/gyro/mpu3050-core.c
index 06162d886b59..b6e05afbe512 100644
--- a/drivers/iio/gyro/mpu3050-core.c
+++ b/drivers/iio/gyro/mpu3050-core.c
@@ -1121,11 +1121,16 @@ static int mpu3050_trigger_probe(struct iio_dev *indio_dev, int irq)
 
 	ret = iio_trigger_register(mpu3050->trig);
 	if (ret)
-		return ret;
+		goto err_iio_trigger;
 
 	indio_dev->trig = iio_trigger_get(mpu3050->trig);
 
 	return 0;
+
+err_iio_trigger:
+	free_irq(mpu3050->irq, mpu3050->trig);
+
+	return ret;
 }
 
 int mpu3050_common_probe(struct device *dev,
-- 
2.53.0
Re: [PATCH v2 2/4] iio: gyro: mpu3050: Fix irq resource leak
Posted by Andy Shevchenko 1 month, 1 week ago
On Mon, Feb 23, 2026 at 08:35:09PM -0600, Ethan Tidmore wrote:
> The interrupt handler is setup but only a few lines down if
> iio_trigger_register() fails the function returns without properly
> releasing the handler:

>         ret = request_threaded_irq(irq,
>                                    mpu3050_irq_handler,
>                                    mpu3050_irq_thread,
>                                    irq_trig,
>                                    mpu3050->trig->name,
>                                    mpu3050->trig);
> 
> ...
> 
>         ret = iio_trigger_register(mpu3050->trig);
>         if (ret)
>                 return ret;
> 
>         indio_dev->trig = iio_trigger_get(mpu3050->trig);
> 
>         return 0;
> }

Same comment, try to avoid citing the existing information (id est
the contents of the file).

> Add cleanup goto to resolve resource leak.
> 
> Detected by Smatch:
> drivers/iio/gyro/mpu3050-core.c:1128 mpu3050_trigger_probe() warn:
> 'irq' from request_threaded_irq() not released on lines: 1124.

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH v2 2/4] iio: gyro: mpu3050: Fix irq resource leak
Posted by Linus Walleij 1 month, 1 week ago
On Tue, Feb 24, 2026 at 3:35 AM Ethan Tidmore <ethantidmore06@gmail.com> wrote:

> The interrupt handler is setup but only a few lines down if
> iio_trigger_register() fails the function returns without properly
> releasing the handler:
>
>         ret = request_threaded_irq(irq,
>                                    mpu3050_irq_handler,
>                                    mpu3050_irq_thread,
>                                    irq_trig,
>                                    mpu3050->trig->name,
>                                    mpu3050->trig);
>
> ...
>
>         ret = iio_trigger_register(mpu3050->trig);
>         if (ret)
>                 return ret;
>
>         indio_dev->trig = iio_trigger_get(mpu3050->trig);
>
>         return 0;
> }
>
> Add cleanup goto to resolve resource leak.
>
> Detected by Smatch:
> drivers/iio/gyro/mpu3050-core.c:1128 mpu3050_trigger_probe() warn:
> 'irq' from request_threaded_irq() not released on lines: 1124.
>
> Fixes: 3904b28efb2c7 ("iio: gyro: Add driver for the MPU-3050 gyroscope")
> Signed-off-by: Ethan Tidmore <ethantidmore06@gmail.com>

Reviewed-by: Linus Walleij <linusw@kernel.org>

Yours,
Linus Walleij