Skip to contentSkip to conversation

iio: chemical: ags02ma: Check for short I2C reads

PATCH Superseded Nikhil Gautam 2 participants 2 messages Oct 13 – Oct 15

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 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.

---
 drivers/iio/chemical/ags02ma.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/iio/chemical/ags02ma.c +6 -0
index 151178d4e8f4..2219965d044f 100644
@@ -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
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · On Tue, 13 Oct 2026 22:47:26 +0530 Nikhil Gautam <[email protected]> wrote:

Check that the I2C receive operation transfers the expected number of bytes before accessing the received data.

Return -EIO if the transfer is incomplete.

---

Fine by me. This is more hardening than a fix so no need for a fixes tag.

Signature · 2 lines
Kind regards,
Joshua Crofts