Skip to content

Commit acc3949

Browse files
amiclausjic23
authored andcommitted
iio: gyro: mpu3050-core: fix pm_runtime error handling
The return value of pm_runtime_get_sync() is not checked, allowing the driver to access hardware that may fail to resume. The device usage count is also unconditionally incremented. 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. Fixes: 3904b28 ("iio: gyro: Add driver for the MPU-3050 gyroscope") Reviewed-by: Linus Walleij <linusw@kernel.org> Signed-off-by: Antoniu Miclaus <antoniu.miclaus@analog.com> Cc: <Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent 91f950b commit acc3949

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

drivers/iio/gyro/mpu3050-core.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,9 @@ static int mpu3050_read_raw(struct iio_dev *indio_dev,
322322
}
323323
case IIO_CHAN_INFO_RAW:
324324
/* Resume device */
325-
pm_runtime_get_sync(mpu3050->dev);
325+
ret = pm_runtime_resume_and_get(mpu3050->dev);
326+
if (ret)
327+
return ret;
326328
mutex_lock(&mpu3050->lock);
327329

328330
ret = mpu3050_set_8khz_samplerate(mpu3050);
@@ -647,14 +649,20 @@ static irqreturn_t mpu3050_trigger_handler(int irq, void *p)
647649
static int mpu3050_buffer_preenable(struct iio_dev *indio_dev)
648650
{
649651
struct mpu3050 *mpu3050 = iio_priv(indio_dev);
652+
int ret;
650653

651-
pm_runtime_get_sync(mpu3050->dev);
654+
ret = pm_runtime_resume_and_get(mpu3050->dev);
655+
if (ret)
656+
return ret;
652657

653658
/* Unless we have OUR trigger active, run at full speed */
654-
if (!mpu3050->hw_irq_trigger)
655-
return mpu3050_set_8khz_samplerate(mpu3050);
659+
if (!mpu3050->hw_irq_trigger) {
660+
ret = mpu3050_set_8khz_samplerate(mpu3050);
661+
if (ret)
662+
pm_runtime_put_autosuspend(mpu3050->dev);
663+
}
656664

657-
return 0;
665+
return ret;
658666
}
659667

660668
static int mpu3050_buffer_postdisable(struct iio_dev *indio_dev)

0 commit comments

Comments
 (0)