Skip to content

Commit 5bdff29

Browse files
sanjay-embeddedjic23
authored andcommitted
iio: accel: mma8452: handle I2C read error(s) in mma8452_read()
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: 96c0cb2 ("iio: mma8452: add support for runtime power management") Signed-off-by: Sanjay Chitroda <sanjayembeddedse@gmail.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
1 parent 97d3098 commit 5bdff29

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

drivers/iio/accel/mma8452.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,8 @@ static int mma8452_read(struct mma8452_data *data, __be16 buf[3])
252252

253253
ret = i2c_smbus_read_i2c_block_data(data->client, MMA8452_OUT_X,
254254
3 * sizeof(__be16), (u8 *)buf);
255+
if (ret < 0)
256+
return ret;
255257

256258
ret = mma8452_set_runtime_pm_state(data->client, false);
257259

0 commit comments

Comments
 (0)