iio: gyro: mpu3050: fix pm_runtime error handling
Subsystems (2)
v3 cover iio: gyro: mpu3050: fix pm_runtime error handling
Fix pm_runtime error handling across the mpu3050 driver. The existing code uses pm_runtime_get_sync() without checking return values, allowing operations to proceed even when the device fails to resume.
Replace pm_runtime_get_sync() with pm_runtime_resume_and_get() and propagate errors appropriately. Unlike pm_runtime_get_sync(), the usage count is not incremented on error.
Changes in v3:
- Rename patches to focus on fix rather than API change
- Add Fixes: tags
- Collect Reviewed-by
Antoniu Miclaus (2):
iio: gyro: mpu3050-i2c: fix pm_runtime error handling in bypass_select
iio: gyro: mpu3050-core: fix pm_runtime error handling
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 v3 1/2 iio: gyro: mpu3050-i2c: fix pm_runtime error handling
pm_runtime_get_sync() does not check its return value, and the function always returns success. This allows I2C mux operations to proceed even when the device fails to resume.
Use pm_runtime_resume_and_get() and propagate its return value to properly handle resume failures.
---
Changes in v3:
- Rename patch to focus on fix rather than API change
- Reword commit message
- Add Fixes: tag
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 v3 2/2 iio: gyro: mpu3050-core: fix pm_runtime error handling
In reply to Antoniu Miclauspm_runtime_get_sync() does not check its return value, allowing the driver to access hardware that may fail to resume. Use pm_runtime_resume_and_get() which propagates errors and avoids incrementing the usage count on failure.
In preenable, add pm_runtime_put_autosuspend() on set_8khz_samplerate() failure since postdisable does not run when preenable fails.
---
Changes in v3:
- Rename patch to focus on fix rather than API change
- Reword commit message
- Add Fixes: tag
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 v3 2/2] iio: gyro: mpu3050-core: fix pm_runtime error handling
Quoted 2 lines · Antoniu Miclaus
pm_runtime_get_sync()does not check its return value, allowing the driver to access hardware that may fail to resume. Use
Try to make lines more filled, this can be achieved by moving "the":
pm_runtime_get_sync() does not check its return value, allowing the driver to access hardware that may fail to resume. Use
Quoted 5 lines
pm_runtime_resume_and_get()which propagates errors and avoids incrementing the usage count on failure.In preenable, add
pm_runtime_put_autosuspend()onset_8khz_samplerate()failure since postdisable does not run when preenable fails.
...
Quoted 12 lines
static int
mpu3050_buffer_preenable(struct iio_dev *indio_dev){drivers/iio/gyro/mpu3050-core.c +4
-2struct 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)
drivers/iio/gyro/mpu3050-core.c static irqreturn_t mpu3050_trigger_handler(int irq, void *p) · line 666
Quoted 10 lines
drivers/iio/gyro/mpu3050-core.c +6
-1-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 ;
These 4 LoCs can be replaced with
return ret;
Quoted 1 line
}
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v3 2/2] iio: gyro: mpu3050-core: fix pm_runtime error handling
In reply to Antoniu MiclausQuoted 1 line · Antoniu Miclaus
pm_runtime_get_sync()does not check its return value, allowing the
I don't want to be too picky but the above is a bit of bad wording :). pm_runtime_get_sync() indeed returns 'int' so the caller is the one not checking it. So we have two things happening:
1) We don't want to ignore the return value from the PM API;
2) We don't want to, unconditionally, increment the device usage count and hence pivot to use pm_runtime_resume_and_get()
- Nuno Sá
Quoted 57 lines
driver to access hardware that may fail to resume. Use
pm_runtime_resume_and_get()which propagates errors and avoids incrementing the usage count on failure.In preenable, add
pm_runtime_put_autosuspend()onset_8khz_samplerate()failure since postdisable does not run when preenable fails.Fixes 3904b28efb2c ("iio: gyro: Add driver for the MPU-3050 gyroscope")Reviewed-by Linus Walleij <[email protected]>Signed-off-by Antoniu Miclaus <[email protected]>---
Changes in v3:
- Rename patch to focus on fix rather than API change
- Reword commit message
- Add Fixes: tagdrivers/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 +6
-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); +return ret; + }
return 0;
}
Quoted 14 lines
-----Original Message-----
From: Antoniu Miclaus <[email protected]>
Sent: Monday, February 9, 2026 1:33 PM
To: Linus Walleij <[email protected]>; Jonathan Cameron <[email protected]>; David Lechner <[email protected]>; Sa, Nuno <[email protected]>; Andy Shevchenko <[email protected]>; [email protected]; linux- [email protected]
Cc: Miclaus, Antoniu <[email protected]>
Subject: [PATCH v3 0/2] iio: gyro: mpu3050: fixpm_runtimeerror handlingFix
pm_runtimeerror handling across the mpu3050 driver. The existing code usespm_runtime_get_sync()without checking return values, allowing operations to proceed even when the device fails to resume.
Quoted 8 lines
Replace
pm_runtime_get_sync()withpm_runtime_resume_and_get()and propagate errors appropriately. Unlikepm_runtime_get_sync(), the usage count is not incremented on error.Changes in v3:
- Rename patches to focus on fix rather than API change
- Add Fixes: tags
- Collect Reviewed-by
Sent by mistake, only the cover-letter. This patch can be ignored.
Quoted 10 lines
Antoniu Miclaus (2):
iio: gyro: mpu3050-i2c: fixpm_runtimeerror handling inbypass_select
iio: gyro: mpu3050-core: fixpm_runtimeerror handlingdrivers/iio/gyro/mpu3050-core.c | 17 +++++++++++++---- drivers/iio/gyro/mpu3050-i2c.c | 3 +-- 2 files changed, 14 insertions(+), 6 deletions(-)--
2.43.0
Quoted 12 lines · Antoniu
Quoted 12 lines
-----Original Message-----
From: Antoniu Miclaus <[email protected]>
Sent: Monday, February 9, 2026 1:33 PMFix
pm_runtimeerror handling across the mpu3050 driver. The existing code usespm_runtime_get_sync()without checking return values, allowing operations to proceed even when the device fails to resume.Replace
pm_runtime_get_sync()withpm_runtime_resume_and_get()and propagate errors appropriately. Unlikepm_runtime_get_sync(), the usage count is not incremented on error.
Quoted 6 lines
Quoted 4 lines
Changes in v3:
- Rename patches to focus on fix rather than API change
- Add Fixes: tags
- Collect Reviewed-bySent by mistake, only the cover-letter. This patch can be ignored.
You lost me. Did you send the cover-letter by a mistake, or the entire series? "This patch" is absent in the cover letter and for the matter of fact, there are two patches in it.
Signature · 2 lines
With Best Regards, Andy Shevchenko
--
Antoniu Miclăuş
Quoted 32 lines
-----Original Message-----
From: Andy Shevchenko <[email protected]>
Sent: Monday, February 9, 2026 3:32 PM
To: Miclaus, Antoniu <[email protected]>
Cc: Linus Walleij <[email protected]>; Jonathan Cameron <[email protected]>; David Lechner <[email protected]>; Sa, Nuno <[email protected]>; Andy Shevchenko <[email protected]>; [email protected]; linux- [email protected]
Subject: Re: [PATCH v3 0/2] iio: gyro: mpu3050: fixpm_runtimeerror handling[External]
Quoted 6 lines · Antoniu
Quoted 6 lines
-----Original Message-----
From: Antoniu Miclaus <[email protected]>
Sent: Monday, February 9, 2026 1:33 PMFix
pm_runtimeerror handling across the mpu3050 driver. The existing code usespm_runtime_get_sync()without checking return values,allowing
Quoted 11 lines
Quoted 10 lines
operations to proceed even when the device fails to resume.
Replace
pm_runtime_get_sync()withpm_runtime_resume_and_get()and propagate errors appropriately. Unlikepm_runtime_get_sync(), the usage count is not incremented on error.Changes in v3:
- Rename patches to focus on fix rather than API change
- Add Fixes: tags
- Collect Reviewed-by
Quoted 5 lines
Quoted 1 line
Sent by mistake, only the cover-letter. This patch can be ignored.
You lost me. Did you send the cover-letter by a mistake, or the entire series? "This patch" is absent in the cover letter and for the matter of fact, there are two patches in it.
I sent by mistake only the cover letter first.
Then I resent the entire patchseries properly (including cover letter).
Quoted 4 lines
--
With Best Regards,
Andy Shevchenko
Quoted 7 lines · Antoniu
Quoted 7 lines
-----Original Message-----
From: Andy Shevchenko <[email protected]>
Sent: Monday, February 9, 2026 3:32 PMQuoted 3 lines · Antoniu
Quoted 3 lines
-----Original Message-----
From: Antoniu Miclaus <[email protected]>
Sent: Monday, February 9, 2026 1:33 PM
...
Quoted 9 lines
Quoted 5 lines
Quoted 1 line
Sent by mistake, only the cover-letter. This patch can be ignored.
You lost me. Did you send the cover-letter by a mistake, or the entire series? "This patch" is absent in the cover letter and for the matter of fact, there are two patches in it.
I sent by mistake only the cover letter first.
Then I resent the entire patchseries properly (including cover letter).
Ah, okay, that explains me having two same mails for cover-letter.
Signature · 2 lines
With Best Regards, Andy Shevchenko