[PATCH 2/4] hwmon: (tps53679) Fix device ID comparison and printing in tps53676_identify()
From: Pradhan, Sanman
Date: Sun Mar 29 2026 - 13:11:58 EST
From: Sanman Pradhan <psanman@xxxxxxxxxxx>
tps53676_identify() uses strncmp() to compare the device ID buffer
against a byte sequence containing embedded non-printable bytes
(\x53\x67\x60). strncmp() is semantically wrong for binary data
comparison; use memcmp() instead.
Additionally, the buffer from i2c_smbus_read_block_data() is not
NUL-terminated, so printing it with "%s" in the error path is
undefined behavior and may read past the buffer. Use "%*ph" to
hex-dump the actual bytes returned.
Also add a short-read guard: if fewer than 5 bytes are returned,
report -EIO (protocol/hardware failure) rather than -ENODEV, since
a truncated response is not the same as a wrong device ID.
Fixes: cb3d37b59012 ("hwmon: (pmbus/tps53679) Add support for TI TPS53676")
Signed-off-by: Sanman Pradhan <psanman@xxxxxxxxxxx>
---
drivers/hwmon/pmbus/tps53679.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/hwmon/pmbus/tps53679.c b/drivers/hwmon/pmbus/tps53679.c
index 1a6abc32afe2..d6600502d6b0 100644
--- a/drivers/hwmon/pmbus/tps53679.c
+++ b/drivers/hwmon/pmbus/tps53679.c
@@ -175,8 +175,12 @@ static int tps53676_identify(struct i2c_client *client,
ret = i2c_smbus_read_block_data(client, PMBUS_IC_DEVICE_ID, buf);
if (ret < 0)
return ret;
- if (strncmp("TI\x53\x67\x60", buf, 5)) {
- dev_err(&client->dev, "Unexpected device ID: %s\n", buf);
+ if (ret < 5) {
+ dev_err(&client->dev, "Short device ID read: %*ph\n", ret, buf);
+ return -EIO;
+ }
+ if (memcmp(buf, "TI\x53\x67\x60", 5)) {
+ dev_err(&client->dev, "Unexpected device ID: %*ph\n", ret, buf);
return -ENODEV;
}
--
2.34.1