Skip to contentSkip to conversation

iio: tmag5273: Fix runtime PM leak on measurement error

PATCH Applied Lars-Peter Clausen 4 participants 4 messages Apr 14, 2023 – Apr 15, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: tmag5273: Fix runtime PM leak on measurement error

The tmag5273 gets a runtime PM reference before reading a measurement and releases it when done. But if the measurement fails the tmag5273_read_raw() function exits before releasing the reference.

Make sure that this error path also releases the runtime PM reference.

Fixes 866a1389174b ("iio: magnetometer: add ti tmag5273 driver")
---
 drivers/iio/magnetometer/tmag5273.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/iio/magnetometer/tmag5273.c +3 -2
index 28bb7efe8df8..e155a75b3cd2 100644
@@ -296,12 +296,13 @@ static int tmag5273_read_raw(struct iio_dev *indio_dev,
 			return ret;
 
 		ret = tmag5273_get_measure(data, &t, &x, &y, &z, &angle, &magnitude);
-		if (ret)
-			return ret;
 
 		pm_runtime_mark_last_busy(data->dev);
 		pm_runtime_put_autosuspend(data->dev);
 
+		if (ret)
+			return ret;
+
 		switch (chan->address) {
 		case TEMPERATURE:
 			*val = t;
Signature · 1 line
2.30.2
Reviewed-by Nuno Sa on v1 1/1
#1 lore raw
Quoted 6 lines · Lars-Peter Clausen

The tmag5273 gets a runtime PM reference before reading a measurement and
releases it when done. But if the measurement fails the tmag5273_read_raw()
function exits before releasing the reference.

Quoted 6 lines

Make sure that this error path also releases the runtime PM reference.

Fixes 866a1389174b ("iio: magnetometer: add ti tmag5273 driver")

---

Quoted 26 lines

 drivers/iio/magnetometer/tmag5273.c | 5 +++--

 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/iio/magnetometer/tmag5273.c +0 -0
index 28bb7efe8df8..e155a75b3cd2 100644
@@ -296,12 +296,13 @@ static int tmag5273_read_raw(struct iio_dev
 *indio_dev,
                         return ret;


                ret = tmag5273_get_measure(data, &t, &x, &y, &z, &angle, &magnitude);
-               if (ret)
-                       return ret;

                pm_runtime_mark_last_busy(data->dev); pm_runtime_put_autosuspend(data->dev);
+               if (ret)
+                       return ret;
+
                switch (chan->address) {
                case TEMPERATURE:
                        *val = t;

maintainer Acked-by
#2 lore raw

Am 14.04.2023 um 07:57 schrieb Nuno Sá:

Quoted 7 lines · Lars-Peter Clausen
Quoted 6 lines

The tmag5273 gets a runtime PM reference before reading a measurement and
releases it when done. But if the measurement fails the tmag5273_read_raw()
function exits before releasing the reference.

Quoted 9 lines
Quoted 6 lines

Make sure that this error path also releases the runtime PM reference.

Fixes 866a1389174b ("iio: magnetometer: add ti tmag5273 driver")

---

Quoted 27 lines
Quoted 26 lines

 drivers/iio/magnetometer/tmag5273.c | 5 +++--

 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/iio/magnetometer/tmag5273.c +0 -0
index 28bb7efe8df8..e155a75b3cd2 100644
@@ -296,12 +296,13 @@ static int tmag5273_read_raw(struct iio_dev
 *indio_dev,
                         return ret;


                ret = tmag5273_get_measure(data, &t, &x, &y, &z, &angle, &magnitude);
-               if (ret)
-                       return ret;

                pm_runtime_mark_last_busy(data->dev); pm_runtime_put_autosuspend(data->dev);
+               if (ret)
+                       return ret;
+
                switch (chan->address) {
                case TEMPERATURE:
                        *val = t;

maintainer Applied
#3 lore raw
Quoted 11 lines · On Fri, 14 Apr 2023 12:17:36 +0200 Gerald Loacker…

Am 14.04.2023 um 07:57 schrieb Nuno Sá:

Quoted 10 lines · Lars-Peter Clausen
Quoted 9 lines

The tmag5273 gets a runtime PM reference before reading a measurement and
releases it when done. But if the measurement fails the tmag5273_read_raw()
function exits before releasing the reference.

Make sure that this error path also releases the runtime PM reference.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Fixes 866a1389174b ("iio: magnetometer: add ti tmag5273 driver")

---

Applied to the fixes-togreg branch of iio.git.

I'm not going to rush this in before the merge window. It might even wait until after rc1 as it would have had any time in linux-next before I send final pull request for the merge window.

Jonathan

Quoted 28 lines
Quoted 28 lines
Quoted 27 lines

 drivers/iio/magnetometer/tmag5273.c | 5 +++--

 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/iio/magnetometer/tmag5273.c +0 -0
index 28bb7efe8df8..e155a75b3cd2 100644
@@ -296,12 +296,13 @@ static int tmag5273_read_raw(struct iio_dev
 *indio_dev,
                         return ret;


                ret = tmag5273_get_measure(data, &t, &x, &y, &z, &angle, &magnitude);
-               if (ret)
-                       return ret;

                pm_runtime_mark_last_busy(data->dev); pm_runtime_put_autosuspend(data->dev);
+               if (ret)
+                       return ret;
+
                switch (chan->address) {
                case TEMPERATURE:
                        *val = t;