Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

hwmon: (tps53679) Fix array access with zero-length block read

i2c_smbus_read_block_data() can return 0, indicating a zero-length
read. When this happens, tps53679_identify_chip() accesses buf[ret - 1]
which is buf[-1], reading one byte before the buffer on the stack.

Fix by changing the check from "ret < 0" to "ret <= 0", treating a
zero-length read as an error (-EIO), which prevents the out-of-bounds
array access.

Also fix a typo in the adjacent comment: "if present" instead of
duplicate "if".

Fixes: 75ca1e5875fe ("hwmon: (pmbus/tps53679) Add support for TPS53685")
Signed-off-by: Sanman Pradhan <psanman@juniper.net>
Link: https://lore.kernel.org/r/20260329170925.34581-2-sanman.pradhan@hpe.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>

authored by

Sanman Pradhan and committed by
Guenter Roeck
0e211f6a 7aaa8047

+3 -3
+3 -3
drivers/hwmon/pmbus/tps53679.c
··· 103 103 } 104 104 105 105 ret = i2c_smbus_read_block_data(client, PMBUS_IC_DEVICE_ID, buf); 106 - if (ret < 0) 107 - return ret; 106 + if (ret <= 0) 107 + return ret < 0 ? ret : -EIO; 108 108 109 - /* Adjust length if null terminator if present */ 109 + /* Adjust length if null terminator is present */ 110 110 buf_len = (buf[ret - 1] != '\x00' ? ret : ret - 1); 111 111 112 112 id_len = strlen(id);