From: Guenter Roeck <linux@roeck-us.net>
To: hanzhijian <hanzhijian1991@gmail.com>
Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] hwmon: (pmbus/ibm-cffps) fix format-truncation warning
Date: Fri, 21 Aug 2026 06:59:20 -0700 [thread overview]
Message-ID: <00ee05d9-1a7c-47b3-8961-e1b63f7bf3fa@roeck-us.net> (raw)
In-Reply-To: <20260821115703.2017414-1-hanzhijian1991@gmail.com>
On 8/21/26 04:57, hanzhijian wrote:
> snprintf() with "%02X" and "%04X" specifiers on an int argument
> triggers -Wformat-truncation (and thus a build failure with
> CONFIG_WERROR) because GCC assumes the int can hold a value wider
> than the destination buffer.
>
> The value comes from i2c_smbus_read_byte_data() and
> i2c_smbus_read_word_data(), which return at most 8 and 16 bits
> respectively, so mask the value to make that explicit and silence
> the warning.
>
So the perceived overflow never happens, and the patch would be
purely to make the compiler happy. I am not going to apply such patches.
Guenter
> Signed-off-by: hanzhijian <hanzhijian1991@gmail.com>
> ---
> drivers/hwmon/pmbus/ibm-cffps.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/hwmon/pmbus/ibm-cffps.c b/drivers/hwmon/pmbus/ibm-cffps.c
> index aad94bcb9..dd7ff3a19 100644
> --- a/drivers/hwmon/pmbus/ibm-cffps.c
> +++ b/drivers/hwmon/pmbus/ibm-cffps.c
> @@ -166,7 +166,7 @@ static ssize_t ibm_cffps_debugfs_read(struct file *file, char __user *buf,
> if (rc < 0)
> goto unlock;
>
> - snprintf(&data[i * 2], 3, "%02X", rc);
> + snprintf(&data[i * 2], 3, "%02X", rc & 0xff);
> }
>
> rc = i * 2;
> @@ -177,7 +177,7 @@ static ssize_t ibm_cffps_debugfs_read(struct file *file, char __user *buf,
> if (rc < 0)
> goto unlock;
>
> - snprintf(&data[i * 4], 5, "%04X", rc);
> + snprintf(&data[i * 4], 5, "%04X", rc & 0xffff);
> }
>
> rc = i * 4;
next prev parent reply other threads:[~2026-08-21 13:59 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-21 11:57 hanzhijian
2026-08-21 13:59 ` Guenter Roeck [this message]
2026-08-21 14:04 ` hanzhijian
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=00ee05d9-1a7c-47b3-8961-e1b63f7bf3fa@roeck-us.net \
--to=linux@roeck-us.net \
--cc=hanzhijian1991@gmail.com \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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®