Re: [PATCH v3 01/10] iio: accel: mma8452: handle I2C read error(s) in mma8452_read()
From: Jonathan Cameron
Date: Mon May 18 2026 - 09:32:47 EST
On Tue, 5 May 2026 23:16:31 +0530
Sanjay Chitroda <sanjayembeddedse@xxxxxxxxx> wrote:
> From: Sanjay Chitroda <sanjayembeddedse@xxxxxxxxx>
>
> Currently, If i2c_smbus_read_i2c_block_data() fails but
> mma8452_set_runtime_pm_state() succeeds, mma8452_read() returns 0.
>
> As a result, the caller mma8452_read_raw() assumes the read was
> successful and proceeds to use a buffer containing uninitialized
> stack memory.
>
> Add proper checking of the I2C read return value and propagate errors
> to the caller.
>
> Fixes: 96c0cb2bbfe0 ("iio: mma8452: add support for runtime power management")
> Signed-off-by: Sanjay Chitroda <sanjayembeddedse@xxxxxxxxx>
Given we don't have reports of this causing trouble and the load
of patches queued up for the driver, I'll take this the slow way
Applied to the testing branch of iio.git.
> ---
> drivers/iio/accel/mma8452.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c
> index 15172ba2972c..cefc7cf4bd83 100644
> --- a/drivers/iio/accel/mma8452.c
> +++ b/drivers/iio/accel/mma8452.c
> @@ -252,6 +252,8 @@ static int mma8452_read(struct mma8452_data *data, __be16 buf[3])
>
> ret = i2c_smbus_read_i2c_block_data(data->client, MMA8452_OUT_X,
> 3 * sizeof(__be16), (u8 *)buf);
> + if (ret < 0)
> + return ret;
>
> ret = mma8452_set_runtime_pm_state(data->client, false);
>