All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] iio: light: ltrf216a: fix runtime PM reference leak in error path
@ 2026-07-13  2:28 Vidhu Sarwal
  2026-07-13 12:28 ` Joshua Crofts
  2026-07-13 12:36 ` Andy Shevchenko
  0 siblings, 2 replies; 3+ messages in thread
From: Vidhu Sarwal @ 2026-07-13  2:28 UTC (permalink / raw)
  To: jic23
  Cc: linux-iio, linux-kernel, shreeya.patel, dlechner, nuno.sa, andy,
	skhan, linux-kernel-mentees, Vidhu Sarwal

ltrf216a_get_lux() acquires a runtime PM reference by calling
ltrf216a_set_power_state(data, true). However, if
ltrf216a_read_data() fails, the function returns immediately without
dropping the reference.

This leaves the runtime PM usage count unbalanced, preventing the device
from autosuspending after a failed read.

Fix this by releasing the runtime PM reference before returning from the
error path.

Fixes: 83f0bcd40d5c ("iio: light: Add support for ltrf216a sensor")
Signed-off-by: Vidhu Sarwal <vidhu.linux@gmail.com>
---
 drivers/iio/light/ltrf216a.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/light/ltrf216a.c b/drivers/iio/light/ltrf216a.c
index 3f34ddc911b4..3ec239eb5831 100644
--- a/drivers/iio/light/ltrf216a.c
+++ b/drivers/iio/light/ltrf216a.c
@@ -247,8 +247,10 @@ static int ltrf216a_get_lux(struct ltrf216a_data *data)
 		return ret;
 
 	greendata = ltrf216a_read_data(data, LTRF216A_ALS_DATA_0);
-	if (greendata < 0)
+	if (greendata < 0) {
+		ltrf216a_set_power_state(data, false);
 		return greendata;
+	}
 
 	ltrf216a_set_power_state(data, false);
 

base-commit: a13c140cc289c0b7b3770bce5b3ad42ab35074aa
-- 
2.53.0


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

* Re: [PATCH] iio: light: ltrf216a: fix runtime PM reference leak in error path
  2026-07-13  2:28 [PATCH] iio: light: ltrf216a: fix runtime PM reference leak in error path Vidhu Sarwal
@ 2026-07-13 12:28 ` Joshua Crofts
  2026-07-13 12:36 ` Andy Shevchenko
  1 sibling, 0 replies; 3+ messages in thread
From: Joshua Crofts @ 2026-07-13 12:28 UTC (permalink / raw)
  To: Vidhu Sarwal
  Cc: jic23, linux-iio, linux-kernel, shreeya.patel, dlechner, nuno.sa,
	andy, skhan, linux-kernel-mentees

On Mon, 13 Jul 2026 07:58:29 +0530
Vidhu Sarwal <vidhu.linux@gmail.com> wrote:

> ltrf216a_get_lux() acquires a runtime PM reference by calling
> ltrf216a_set_power_state(data, true). However, if
> ltrf216a_read_data() fails, the function returns immediately without
> dropping the reference.
> 
> This leaves the runtime PM usage count unbalanced, preventing the device
> from autosuspending after a failed read.
> 
> Fix this by releasing the runtime PM reference before returning from the
> error path.
> 
> Fixes: 83f0bcd40d5c ("iio: light: Add support for ltrf216a sensor")
> Signed-off-by: Vidhu Sarwal <vidhu.linux@gmail.com>
> ---
>  drivers/iio/light/ltrf216a.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/light/ltrf216a.c b/drivers/iio/light/ltrf216a.c
> index 3f34ddc911b4..3ec239eb5831 100644
> --- a/drivers/iio/light/ltrf216a.c
> +++ b/drivers/iio/light/ltrf216a.c
> @@ -247,8 +247,10 @@ static int ltrf216a_get_lux(struct ltrf216a_data *data)
>  		return ret;
>  
>  	greendata = ltrf216a_read_data(data, LTRF216A_ALS_DATA_0);
> -	if (greendata < 0)
> +	if (greendata < 0) {
> +		ltrf216a_set_power_state(data, false);
>  		return greendata;
> +	}
>  
>  	ltrf216a_set_power_state(data, false);

LGTM, Sashiko had an issue with the fact that pm_runtime_mark_last_busy() isn't
called before autosuspending, however pm_runtime_put_autosuspend() already calls
this function in its body.

Reviewed-by: Joshua Crofts <joshua.crofts1@gmail.com>

-- 
Kind regards

CJD

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

* Re: [PATCH] iio: light: ltrf216a: fix runtime PM reference leak in error path
  2026-07-13  2:28 [PATCH] iio: light: ltrf216a: fix runtime PM reference leak in error path Vidhu Sarwal
  2026-07-13 12:28 ` Joshua Crofts
@ 2026-07-13 12:36 ` Andy Shevchenko
  1 sibling, 0 replies; 3+ messages in thread
From: Andy Shevchenko @ 2026-07-13 12:36 UTC (permalink / raw)
  To: Vidhu Sarwal
  Cc: jic23, linux-iio, linux-kernel, shreeya.patel, dlechner, nuno.sa,
	andy, skhan, linux-kernel-mentees

On Mon, Jul 13, 2026 at 07:58:29AM +0530, Vidhu Sarwal wrote:
> ltrf216a_get_lux() acquires a runtime PM reference by calling
> ltrf216a_set_power_state(data, true). However, if
> ltrf216a_read_data() fails, the function returns immediately without
> dropping the reference.
> 
> This leaves the runtime PM usage count unbalanced, preventing the device
> from autosuspending after a failed read.
> 
> Fix this by releasing the runtime PM reference before returning from the
> error path.

...

> static int ltrf216a_get_lux(struct ltrf216a_data *data)

>  	greendata = ltrf216a_read_data(data, LTRF216A_ALS_DATA_0);
> -	if (greendata < 0)
> +	if (greendata < 0) {
> +		ltrf216a_set_power_state(data, false);
>  		return greendata;
> +	}
>  
>  	ltrf216a_set_power_state(data, false);

Wouldn't be simpler to do

	greendata = ltrf216a_read_data(data, LTRF216A_ALS_DATA_0);

	ltrf216a_set_power_state(data, false);

	if (greendata < 0)
		return greendata;

?

Not insisting on this. Up to Jonathan and others to decide.


-- 
With Best Regards,
Andy Shevchenko



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

end of thread, other threads:[~2026-07-13 12:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-13  2:28 [PATCH] iio: light: ltrf216a: fix runtime PM reference leak in error path Vidhu Sarwal
2026-07-13 12:28 ` Joshua Crofts
2026-07-13 12:36 ` Andy Shevchenko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.