iio: chemical: ags02ma: Check for short I2C reads
Subsystems (2)
PATCH v2 1/1 iio: chemical: ags02ma: Check for short I2C reads
Check that the I2C receive operation transfers the expected number of bytes before accessing the received data.
Return -EIO if the transfer is incomplete.
Fixes d58013f39b30 ("iio: chemical: add support for Aosong AGS02MA")
Signed-off-by Nikhil Gautam <[email protected]>
--- drivers/iio/chemical/ags02ma.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/iio/chemical/ags02ma.c +6 -0
@@ -61,6 +61,12 @@ static int ags02ma_register_read(struct i2c_client *client, u8 reg, u16 delay,return ret; } +if (ret !=sizeof (read_buffer)) { +dev_err (&client->dev, +"Short read from register 0x%x\n" , reg); +return -EIO ; + } + crc =crc8 (ags02ma_crc8_table, (u8 *)&read_buffer.data,sizeof (read_buffer.data),AGS02MA_CRC8_INIT );if (crc != read_buffer.crc) {
Signature · 1 line
2.39.5
Jonathan Cameron
maintainerQuoted 7 lines · On Sat, 17 Oct 2026 15:16:39 +0530 Nikhil Gautam <[email protected]> wrote:
Check that the I2C receive operation transfers the expected number of bytes before accessing the received data.
Return
-EIOif the transfer is incomplete.Fixes d58013f39b30 ("iio: chemical: add support for Aosong AGS02MA")Signed-off-by Nikhil Gautam <[email protected]>
Hi Nikhil,
Given in practice we are very unlikely to ever see this condition I've not rushed this one in. Next cycle is soon enough.
As such, applied to the testing branch of iio.git.
Jonathan
Quoted 21 lines
--- drivers/iio/chemical/ags02ma.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/iio/chemical/ags02ma.c +6
-0@@ -61,6 +61,12 @@ static int ags02ma_register_read(struct i2c_client *client, u8 reg, u16 delay,return ret; } +if (ret !=sizeof (read_buffer)) { +dev_err (&client->dev, +"Short read from register 0x%x\n" , reg); +return -EIO ; + } + crc =crc8 (ags02ma_crc8_table, (u8 *)&read_buffer.data,sizeof (read_buffer.data),AGS02MA_CRC8_INIT );if (crc != read_buffer.crc) {