iio: light: ltrf216a: fix runtime PM reference leak in error path
PATCH 1/1 iio: light: ltrf216a: fix runtime PM reference leak in error path
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.
--- drivers/iio/light/ltrf216a.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/iio/light/ltrf216a.c +3 -1
@@ -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
Signature · 1 line
2.53.0
Quoted 22 lines · On Mon, 13 Jul 2026 07:58:29 +0530 Vidhu Sarwal <[email protected]> wrote:
ltrf216a_get_lux()acquires a runtime PM reference by callingltrf216a_set_power_state(data, true). However, ifltrf216a_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 <[email protected]>--- drivers/iio/light/ltrf216a.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/iio/light/ltrf216a.c +0
-0
drivers/iio/light/ltrf216a.c static int ltrf216a_get_lux(struct ltrf216a_data *data) · line 255
Quoted 10 lines
drivers/iio/light/ltrf216a.c +3
-1@@ -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.
Signature · 3 lines
Kind regards CJD
Quoted 10 lines · Vidhu Sarwal
ltrf216a_get_lux()acquires a runtime PM reference by callingltrf216a_set_power_state(data, true). However, ifltrf216a_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.
...
drivers/iio/light/ltrf216a.c static int ltrf216a_get_lux(struct ltrf216a_data *data) · line 255
Quoted 10 lines
static int
ltrf216a_get_lux(struct ltrf216a_data *data)drivers/iio/light/ltrf216a.c +3
-1greendata =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.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Jonathan Cameron
AppliedQuoted 34 lines · On Mon, 13 Jul 2026 15:36:51 +0300 Andy Shevchenko…
Quoted 10 lines · Vidhu Sarwal
ltrf216a_get_lux()acquires a runtime PM reference by callingltrf216a_set_power_state(data, true). However, ifltrf216a_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.
...
Review
Quoted 10 lines
static int
ltrf216a_get_lux(struct ltrf216a_data *data)(quoted diff) +3
-1greendata = 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;
Quoted 3 lines
?
Not insisting on this. Up to Jonathan and others to decide.
I merged a slight variant on what Andy has here to keep the greendata assignment and check closer together.
drivers/iio/light/ltrf216a.c +1 -2
@@ -248,11 +248,10 @@ static int ltrf216a_get_lux(struct ltrf216a_data *data)return ret; greendata =ltrf216a_read_data (data,LTRF216A_ALS_DATA_0 ); +ltrf216a_set_power_state (data, false);if (greendata <0 )return greendata; -ltrf216a_set_power_state (data, false); - lux = greendata * data->info->lux_multiplier *LTRF216A_WIN_FAC ;return lux;