iio: gyro: mpu3050: use pm_runtime_resume_and_get()
Subsystems (2)
v2 cover iio: gyro: mpu3050: use pm_runtime_resume_and_get()
Replace pm_runtime_get_sync() with pm_runtime_resume_and_get() across the mpu3050 driver. Unlike pm_runtime_get_sync(), the usage count is not incremented on error.
Changes in v2:
- Add cover letter
- Reword commit messages
Antoniu Miclaus (2):
iio: gyro: mpu3050-i2c: use pm_runtime_resume_and_get()
iio: gyro: mpu3050-core: use pm_runtime_resume_and_get()
drivers/iio/gyro/mpu3050-core.c | 17 +++++++++++++---- drivers/iio/gyro/mpu3050-i2c.c | 3 +-- 2 files changed, 14 insertions(+), 6 deletions(-)
Signature · 1 line
2.43.0
PATCH v2 1/2 iio: gyro: mpu3050-i2c: use pm_runtime_resume_and_get()
Replace pm_runtime_get_sync() with pm_runtime_resume_and_get() in bypass_select() and return its result directly. Unlike pm_runtime_get_sync(), the usage count is not incremented on error.
--- drivers/iio/gyro/mpu3050-i2c.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/iio/gyro/mpu3050-i2c.c +1 -2
@@ -19,8 +19,7 @@ static int mpu3050_i2c_bypass_select(struct i2c_mux_core *mux, u32 chan_id)struct mpu3050 *mpu3050 =i2c_mux_priv (mux);/* Just power up the device, that is all that is needed */ -pm_runtime_get_sync (mpu3050->dev); -return 0 ; +return pm_runtime_resume_and_get (mpu3050->dev); }static int mpu3050_i2c_bypass_deselect (struct i2c_mux_core *mux,u32 chan_id)
Signature · 1 line
2.43.0
PATCH v2 2/2 iio: gyro: mpu3050-core: use pm_runtime_resume_and_get()
In reply to Antoniu MiclausReplace 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.
--- drivers/iio/gyro/mpu3050-core.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)
drivers/iio/gyro/mpu3050-core.c +13 -4
@@ -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 ; }
Signature · 1 line
2.43.0
Re: [PATCH v2 2/2] iio: gyro: mpu3050-core: use pm_runtime_resume_and_get()
Quoted 9 lines · Antoniu Miclaus
Replace
pm_runtime_get_sync()withpm_runtime_resume_and_get()inmpu3050_read_raw()andmpu3050_buffer_preenable(). Unlikepm_runtime_get_sync(), the usage count is not incremented on error.In preenable, call
pm_runtime_put_autosuspend()ifset_8khz_samplerate()fails since postdisable won't be called on preenable failure.Signed-off-by Antoniu Miclaus <[email protected]>---
To me this is more than just reference counting. It's also about proper error handling.
- Nuno Sá
Quoted 36 lines
drivers/iio/gyro/mpu3050-core.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)drivers/iio/gyro/mpu3050-core.c +0
-0@@ -322,7 +322,9 @@ static int mpu3050_read_raw(struct iio_dev *indio_dev, }case
IIO_CHAN_INFO_RAW:
/* Resume device */drivers/iio/gyro/mpu3050-core.c +3
-1-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);drivers/iio/gyro/mpu3050-core.c +1
-0@@ -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;drivers/iio/gyro/mpu3050-core.c +3
-1-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 */drivers/iio/gyro/mpu3050-core.c +4
-2-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);
Jonathan Cameron
maintainerRe: [PATCH v2 2/2] iio: gyro: mpu3050-core: use pm_runtime_resume_and_get()
Quoted 5 lines · On Tue, 03 Feb 2026 09:45:34 +0000 Nuno Sá <[email protected]> wrote:
Quoted 4 lines · Antoniu Miclaus
Replace
pm_runtime_get_sync()withpm_runtime_resume_and_get()inmpu3050_read_raw()andmpu3050_buffer_preenable(). Unlikepm_runtime_get_sync(), the usage count is not incremented on error.
Quoted 7 lines
Quoted 5 lines
In preenable, call
pm_runtime_put_autosuspend()ifset_8khz_samplerate()fails since postdisable won't be called on preenable failure.Signed-off-by Antoniu Miclaus <[email protected]>---
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
Quoted 39 lines
- Nuno Sá
Quoted 36 lines
drivers/iio/gyro/mpu3050-core.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)drivers/iio/gyro/mpu3050-core.c +0
-0@@ -322,7 +322,9 @@ static int mpu3050_read_raw(struct iio_dev *indio_dev, }case
IIO_CHAN_INFO_RAW:
/* Resume device */drivers/iio/gyro/mpu3050-core.c +3
-1-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);drivers/iio/gyro/mpu3050-core.c +1
-0@@ -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;drivers/iio/gyro/mpu3050-core.c +3
-1-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 */drivers/iio/gyro/mpu3050-core.c +4
-2-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()
In reply to Antoniu MiclausQuoted 8 lines · Antoniu Miclaus
Replace
pm_runtime_get_sync()withpm_runtime_resume_and_get()inmpu3050_read_raw()andmpu3050_buffer_preenable(). Unlikepm_runtime_get_sync(), the usage count is not incremented on error.In preenable, call
pm_runtime_put_autosuspend()ifset_8khz_samplerate()fails since postdisable won't be called on preenable failure.Signed-off-by Antoniu Miclaus <[email protected]>
Yours,
Linus Walleij