diff mbox series

iio: tmag5273: Fix runtime PM leak on measurement error

Message ID 20230414013752.498767-1-lars@metafoo.de (mailing list archive)
State Accepted
Headers show
Series iio: tmag5273: Fix runtime PM leak on measurement error | expand

Commit Message

Lars-Peter Clausen April 14, 2023, 1:37 a.m. UTC
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")
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/iio/magnetometer/tmag5273.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Nuno Sá April 14, 2023, 5:57 a.m. UTC | #1
On Thu, 2023-04-13 at 18:37 -0700, Lars-Peter Clausen wrote:
> 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")
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
> ---

Reviewed-by: Nuno Sa <nuno.sa@analog.com>

>  drivers/iio/magnetometer/tmag5273.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/magnetometer/tmag5273.c
> b/drivers/iio/magnetometer/tmag5273.c
> index 28bb7efe8df8..e155a75b3cd2 100644
> --- a/drivers/iio/magnetometer/tmag5273.c
> +++ b/drivers/iio/magnetometer/tmag5273.c
> @@ -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;
Gerald Loacker April 14, 2023, 10:17 a.m. UTC | #2
Am 14.04.2023 um 07:57 schrieb Nuno Sá:
> On Thu, 2023-04-13 at 18:37 -0700, Lars-Peter Clausen wrote:
>> 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")
>> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
>> ---
> 
> Reviewed-by: Nuno Sa <nuno.sa@analog.com>
> 

Acked-by: Gerald Loacker <gerald.loacker@wolfvision.net>

>>  drivers/iio/magnetometer/tmag5273.c | 5 +++--
>>  1 file changed, 3 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/iio/magnetometer/tmag5273.c
>> b/drivers/iio/magnetometer/tmag5273.c
>> index 28bb7efe8df8..e155a75b3cd2 100644
>> --- a/drivers/iio/magnetometer/tmag5273.c
>> +++ b/drivers/iio/magnetometer/tmag5273.c
>> @@ -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;
>
Jonathan Cameron April 15, 2023, 3:20 p.m. UTC | #3
On Fri, 14 Apr 2023 12:17:36 +0200
Gerald Loacker <gerald.loacker@wolfvision.net> wrote:

> Am 14.04.2023 um 07:57 schrieb Nuno Sá:
> > On Thu, 2023-04-13 at 18:37 -0700, Lars-Peter Clausen wrote:  
> >> 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")
> >> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
> >> ---  
> > 
> > Reviewed-by: Nuno Sa <nuno.sa@analog.com>
> >   
> 
> Acked-by: Gerald Loacker <gerald.loacker@wolfvision.net>
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

> 
> >>  drivers/iio/magnetometer/tmag5273.c | 5 +++--
> >>  1 file changed, 3 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/drivers/iio/magnetometer/tmag5273.c
> >> b/drivers/iio/magnetometer/tmag5273.c
> >> index 28bb7efe8df8..e155a75b3cd2 100644
> >> --- a/drivers/iio/magnetometer/tmag5273.c
> >> +++ b/drivers/iio/magnetometer/tmag5273.c
> >> @@ -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;  
> >
diff mbox series

Patch

diff --git a/drivers/iio/magnetometer/tmag5273.c b/drivers/iio/magnetometer/tmag5273.c
index 28bb7efe8df8..e155a75b3cd2 100644
--- a/drivers/iio/magnetometer/tmag5273.c
+++ b/drivers/iio/magnetometer/tmag5273.c
@@ -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;