[PATCH v2 2/2] iio: gyro: mpu3050-core: use pm_runtime_resume_and_get()

Antoniu Miclaus posted 2 patches 6 days ago
[PATCH v2 2/2] iio: gyro: mpu3050-core: use pm_runtime_resume_and_get()
Posted by Antoniu Miclaus 6 days ago
Replace pm_runtime_get_sync() with pm_runtime_resume_and_get() in
mpu3050_read_raw() and mpu3050_buffer_preenable(). Unlike
pm_runtime_get_sync(), the usage count is not incremented on error.

In preenable, call pm_runtime_put_autosuspend() if set_8khz_samplerate()
fails since postdisable won't be called on preenable failure.

Signed-off-by: Antoniu Miclaus <antoniu.miclaus@analog.com>
---
 drivers/iio/gyro/mpu3050-core.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/drivers/iio/gyro/mpu3050-core.c b/drivers/iio/gyro/mpu3050-core.c
index ee2fcd20545d..1cc421eb4782 100644
--- a/drivers/iio/gyro/mpu3050-core.c
+++ b/drivers/iio/gyro/mpu3050-core.c
@@ -322,7 +322,9 @@ static int mpu3050_read_raw(struct iio_dev *indio_dev,
 		}
 	case IIO_CHAN_INFO_RAW:
 		/* Resume device */
-		pm_runtime_get_sync(mpu3050->dev);
+		ret = pm_runtime_resume_and_get(mpu3050->dev);
+		if (ret)
+			return ret;
 		mutex_lock(&mpu3050->lock);
 
 		ret = mpu3050_set_8khz_samplerate(mpu3050);
@@ -647,12 +649,19 @@ static irqreturn_t mpu3050_trigger_handler(int irq, void *p)
 static int mpu3050_buffer_preenable(struct iio_dev *indio_dev)
 {
 	struct mpu3050 *mpu3050 = iio_priv(indio_dev);
+	int ret;
 
-	pm_runtime_get_sync(mpu3050->dev);
+	ret = pm_runtime_resume_and_get(mpu3050->dev);
+	if (ret)
+		return ret;
 
 	/* Unless we have OUR trigger active, run at full speed */
-	if (!mpu3050->hw_irq_trigger)
-		return mpu3050_set_8khz_samplerate(mpu3050);
+	if (!mpu3050->hw_irq_trigger) {
+		ret = mpu3050_set_8khz_samplerate(mpu3050);
+		if (ret)
+			pm_runtime_put_autosuspend(mpu3050->dev);
+		return ret;
+	}
 
 	return 0;
 }
-- 
2.43.0
Re: [PATCH v2 2/2] iio: gyro: mpu3050-core: use pm_runtime_resume_and_get()
Posted by Linus Walleij 17 hours ago
On Mon, Feb 2, 2026 at 3:57 PM Antoniu Miclaus
<antoniu.miclaus@analog.com> wrote:

> Replace pm_runtime_get_sync() with pm_runtime_resume_and_get() in
> mpu3050_read_raw() and mpu3050_buffer_preenable(). Unlike
> pm_runtime_get_sync(), the usage count is not incremented on error.
>
> In preenable, call pm_runtime_put_autosuspend() if set_8khz_samplerate()
> fails since postdisable won't be called on preenable failure.
>
> Signed-off-by: Antoniu Miclaus <antoniu.miclaus@analog.com>

Reviewed-by: Linus Walleij <linusw@kernel.org>

Yours,
Linus Walleij
Re: [PATCH v2 2/2] iio: gyro: mpu3050-core: use pm_runtime_resume_and_get()
Posted by Nuno Sá 5 days, 5 hours ago
On Mon, 2026-02-02 at 16:56 +0200, Antoniu Miclaus wrote:
> Replace pm_runtime_get_sync() with pm_runtime_resume_and_get() in
> mpu3050_read_raw() and mpu3050_buffer_preenable(). Unlike
> pm_runtime_get_sync(), the usage count is not incremented on error.
> 
> In preenable, call pm_runtime_put_autosuspend() if set_8khz_samplerate()
> fails since postdisable won't be called on preenable failure.
> 
> Signed-off-by: Antoniu Miclaus <antoniu.miclaus@analog.com>
> ---

To me this is more than just reference counting. It's also about proper error handling.

- Nuno Sá

>  drivers/iio/gyro/mpu3050-core.c | 17 +++++++++++++----
>  1 file changed, 13 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/iio/gyro/mpu3050-core.c b/drivers/iio/gyro/mpu3050-core.c
> index ee2fcd20545d..1cc421eb4782 100644
> --- a/drivers/iio/gyro/mpu3050-core.c
> +++ b/drivers/iio/gyro/mpu3050-core.c
> @@ -322,7 +322,9 @@ static int mpu3050_read_raw(struct iio_dev *indio_dev,
>  		}
>  	case IIO_CHAN_INFO_RAW:
>  		/* Resume device */
> -		pm_runtime_get_sync(mpu3050->dev);
> +		ret = pm_runtime_resume_and_get(mpu3050->dev);
> +		if (ret)
> +			return ret;
>  		mutex_lock(&mpu3050->lock);
>  
>  		ret = mpu3050_set_8khz_samplerate(mpu3050);
> @@ -647,12 +649,19 @@ static irqreturn_t mpu3050_trigger_handler(int irq, void *p)
>  static int mpu3050_buffer_preenable(struct iio_dev *indio_dev)
>  {
>  	struct mpu3050 *mpu3050 = iio_priv(indio_dev);
> +	int ret;
>  
> -	pm_runtime_get_sync(mpu3050->dev);
> +	ret = pm_runtime_resume_and_get(mpu3050->dev);
> +	if (ret)
> +		return ret;
>  
>  	/* Unless we have OUR trigger active, run at full speed */
> -	if (!mpu3050->hw_irq_trigger)
> -		return mpu3050_set_8khz_samplerate(mpu3050);
> +	if (!mpu3050->hw_irq_trigger) {
> +		ret = mpu3050_set_8khz_samplerate(mpu3050);
> +		if (ret)
> +			pm_runtime_put_autosuspend(mpu3050->dev);
Re: [PATCH v2 2/2] iio: gyro: mpu3050-core: use pm_runtime_resume_and_get()
Posted by Jonathan Cameron 23 hours ago
On Tue, 03 Feb 2026 09:45:34 +0000
Nuno Sá <noname.nuno@gmail.com> wrote:

> On Mon, 2026-02-02 at 16:56 +0200, Antoniu Miclaus wrote:
> > Replace pm_runtime_get_sync() with pm_runtime_resume_and_get() in
> > mpu3050_read_raw() and mpu3050_buffer_preenable(). Unlike
> > pm_runtime_get_sync(), the usage count is not incremented on error.
> > 
> > In preenable, call pm_runtime_put_autosuspend() if set_8khz_samplerate()
> > fails since postdisable won't be called on preenable failure.
> > 
> > Signed-off-by: Antoniu Miclaus <antoniu.miclaus@analog.com>
> > ---  
> 
> To me this is more than just reference counting. It's also about proper error handling.
Agreed. I think these should both have fixes tags
and a commit message that calls out a little more clearly what is being fixed.


Jonathan

> 
> - Nuno Sá
> 
> >  drivers/iio/gyro/mpu3050-core.c | 17 +++++++++++++----
> >  1 file changed, 13 insertions(+), 4 deletions(-)
> > 
> > diff --git a/drivers/iio/gyro/mpu3050-core.c b/drivers/iio/gyro/mpu3050-core.c
> > index ee2fcd20545d..1cc421eb4782 100644
> > --- a/drivers/iio/gyro/mpu3050-core.c
> > +++ b/drivers/iio/gyro/mpu3050-core.c
> > @@ -322,7 +322,9 @@ static int mpu3050_read_raw(struct iio_dev *indio_dev,
> >  		}
> >  	case IIO_CHAN_INFO_RAW:
> >  		/* Resume device */
> > -		pm_runtime_get_sync(mpu3050->dev);
> > +		ret = pm_runtime_resume_and_get(mpu3050->dev);
> > +		if (ret)
> > +			return ret;
> >  		mutex_lock(&mpu3050->lock);
> >  
> >  		ret = mpu3050_set_8khz_samplerate(mpu3050);
> > @@ -647,12 +649,19 @@ static irqreturn_t mpu3050_trigger_handler(int irq, void *p)
> >  static int mpu3050_buffer_preenable(struct iio_dev *indio_dev)
> >  {
> >  	struct mpu3050 *mpu3050 = iio_priv(indio_dev);
> > +	int ret;
> >  
> > -	pm_runtime_get_sync(mpu3050->dev);
> > +	ret = pm_runtime_resume_and_get(mpu3050->dev);
> > +	if (ret)
> > +		return ret;
> >  
> >  	/* Unless we have OUR trigger active, run at full speed */
> > -	if (!mpu3050->hw_irq_trigger)
> > -		return mpu3050_set_8khz_samplerate(mpu3050);
> > +	if (!mpu3050->hw_irq_trigger) {
> > +		ret = mpu3050_set_8khz_samplerate(mpu3050);
> > +		if (ret)
> > +			pm_runtime_put_autosuspend(mpu3050->dev);