[PATCH] iio: light: bh1780: fix PM runtime leak on error path

Antoniu Miclaus posted 1 patch 1 week ago
drivers/iio/light/bh1780.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] iio: light: bh1780: fix PM runtime leak on error path
Posted by Antoniu Miclaus 1 week ago
Move pm_runtime_put_autosuspend() before the error check to ensure
the PM runtime reference count is always decremented after
pm_runtime_get_sync(), regardless of whether the read operation
succeeds or fails.

Fixes: 1f0477f18306 ("iio: light: new driver for the ROHM BH1780")
Signed-off-by: Antoniu Miclaus <antoniu.miclaus@analog.com>
---
 drivers/iio/light/bh1780.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/light/bh1780.c b/drivers/iio/light/bh1780.c
index 5d3c6d5276ba..a740d1f992a8 100644
--- a/drivers/iio/light/bh1780.c
+++ b/drivers/iio/light/bh1780.c
@@ -109,9 +109,9 @@ static int bh1780_read_raw(struct iio_dev *indio_dev,
 		case IIO_LIGHT:
 			pm_runtime_get_sync(&bh1780->client->dev);
 			value = bh1780_read_word(bh1780, BH1780_REG_DLOW);
+			pm_runtime_put_autosuspend(&bh1780->client->dev);
 			if (value < 0)
 				return value;
-			pm_runtime_put_autosuspend(&bh1780->client->dev);
 			*val = value;
 
 			return IIO_VAL_INT;
-- 
2.43.0
Re: [PATCH] iio: light: bh1780: fix PM runtime leak on error path
Posted by Linus Walleij 1 week ago
On Fri, Jan 30, 2026 at 12:31 PM Antoniu Miclaus
<antoniu.miclaus@analog.com> wrote:

> Move pm_runtime_put_autosuspend() before the error check to ensure
> the PM runtime reference count is always decremented after
> pm_runtime_get_sync(), regardless of whether the read operation
> succeeds or fails.
>
> Fixes: 1f0477f18306 ("iio: light: new driver for the ROHM BH1780")
> Signed-off-by: Antoniu Miclaus <antoniu.miclaus@analog.com>

This looks right!
Reviewed-by: Linus Walleij <linusw@kernel.org>

Yours,
Linus Walleij
Re: [PATCH] iio: light: bh1780: fix PM runtime leak on error path
Posted by Jonathan Cameron 6 days, 15 hours ago
On Fri, 30 Jan 2026 14:16:36 +0100
Linus Walleij <linusw@kernel.org> wrote:

> On Fri, Jan 30, 2026 at 12:31 PM Antoniu Miclaus
> <antoniu.miclaus@analog.com> wrote:
> 
> > Move pm_runtime_put_autosuspend() before the error check to ensure
> > the PM runtime reference count is always decremented after
> > pm_runtime_get_sync(), regardless of whether the read operation
> > succeeds or fails.
> >
> > Fixes: 1f0477f18306 ("iio: light: new driver for the ROHM BH1780")
> > Signed-off-by: Antoniu Miclaus <antoniu.miclaus@analog.com>  
> 
> This looks right!
> Reviewed-by: Linus Walleij <linusw@kernel.org>
I've applied this to my local tree for now.  Given where we are in the
cycle this likely won't go out until after the merge window when
I have rebased on rc1.

Thanks,

Jonathan

> 
> Yours,
> Linus Walleij