From: Guenter Roeck <linux@roeck-us.net>
To: "Pradhan, Sanman" <sanman.pradhan@hpe.com>,
"linux-hwmon@vger.kernel.org" <linux-hwmon@vger.kernel.org>
Cc: "Delphine_CC_Chiu@Wiwynn.com" <Delphine_CC_Chiu@Wiwynn.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Sanman Pradhan <psanman@juniper.net>
Subject: Re: [PATCH 2/4] hwmon: (tps53679) Fix device ID comparison and printing in tps53676_identify()
Date: Sun, 29 Mar 2026 11:34:42 -0700 [thread overview]
Message-ID: <d37357a2-90b0-49fc-8af8-434ebac8ca6b@roeck-us.net> (raw)
In-Reply-To: <20260329170925.34581-3-sanman.pradhan@hpe.com>
Hi,
On 3/29/26 10:09, Pradhan, Sanman wrote:
> From: Sanman Pradhan <psanman@juniper.net>
>
> 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.
>
Ah, but we don't know and can not assume that this is a truncated ID.
It might as well be some other device.
> Fixes: cb3d37b59012 ("hwmon: (pmbus/tps53679) Add support for TI TPS53676")
> Signed-off-by: Sanman Pradhan <psanman@juniper.net>
> ---
> 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;
This is not an -EIO: It suggests a different device. Please change the comparison
to "ret != 0" and return -ENODEV. In other words,
> + }
> + if (memcmp(buf, "TI\x53\x67\x60", 5)) {
Just change the original code. The expected device ID, according to the datasheet,
is, in hex, "54 49 53 67 60 00", with a terminating 0x00. So, when using memcmp,
the comparison should be something like
if (ret != 6 || memcmp(buf, "TI\x53\x67\x60\x00", 6)) {
Thanks,
Guenter
next prev parent reply other threads:[~2026-03-29 18:34 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-29 17:09 [PATCH 0/4] hwmon: PMBus driver bug fixes Pradhan, Sanman
2026-03-29 17:09 ` [PATCH 1/4] hwmon: (tps53679) Fix array access with zero-length block read Pradhan, Sanman
2026-03-29 19:10 ` Guenter Roeck
2026-03-29 17:09 ` [PATCH 2/4] hwmon: (tps53679) Fix device ID comparison and printing in tps53676_identify() Pradhan, Sanman
2026-03-29 18:34 ` Guenter Roeck [this message]
2026-03-29 17:09 ` [PATCH 3/4] hwmon: (pxe1610) Check return value of page-select write in probe Pradhan, Sanman
2026-03-29 19:13 ` Guenter Roeck
2026-03-29 17:09 ` [PATCH 4/4] hwmon: (ltc4286) Add missing MODULE_IMPORT_NS("PMBUS") Pradhan, Sanman
2026-03-29 19:13 ` Guenter Roeck
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d37357a2-90b0-49fc-8af8-434ebac8ca6b@roeck-us.net \
--to=linux@roeck-us.net \
--cc=Delphine_CC_Chiu@Wiwynn.com \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=psanman@juniper.net \
--cc=sanman.pradhan@hpe.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®