]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
hwmon: (tps53679) Fix device ID comparison and printing in tps53676_identify()
authorSanman Pradhan <psanman@juniper.net>
Mon, 30 Mar 2026 15:56:40 +0000 (15:56 +0000)
committerGuenter Roeck <linux@roeck-us.net>
Mon, 30 Mar 2026 17:46:53 +0000 (10:46 -0700)
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.

Per the datasheet, the expected device ID is the 6-byte sequence
54 49 53 67 60 00 ("TI\x53\x67\x60\x00"), so compare all 6 bytes
including the trailing NUL.

Fixes: cb3d37b59012 ("hwmon: (pmbus/tps53679) Add support for TI TPS53676")
Signed-off-by: Sanman Pradhan <psanman@juniper.net>
Link: https://lore.kernel.org/r/20260330155618.77403-1-sanman.pradhan@hpe.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/pmbus/tps53679.c

index 3bca543817a6050ca787cbf5a38c9c19f3c2c118..249974c13aa399da4d9e6e6867e064dd918defb8 100644 (file)
@@ -175,8 +175,8 @@ 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 != 6 || memcmp(buf, "TI\x53\x67\x60\x00", 6)) {
+               dev_err(&client->dev, "Unexpected device ID: %*ph\n", ret, buf);
                return -ENODEV;
        }