* [PATCH] hwmon: (pmbus/ibm-cffps) fix format-truncation warning
@ 2026-08-21 11:57 hanzhijian
2026-08-21 12:05 ` sashiko-bot
2026-08-21 13:59 ` Guenter Roeck
0 siblings, 2 replies; 4+ messages in thread
From: hanzhijian @ 2026-08-21 11:57 UTC (permalink / raw)
To: Guenter Roeck; +Cc: linux-hwmon, linux-kernel, hanzhijian
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.
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;
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] hwmon: (pmbus/ibm-cffps) fix format-truncation warning
2026-08-21 11:57 [PATCH] hwmon: (pmbus/ibm-cffps) fix format-truncation warning hanzhijian
@ 2026-08-21 12:05 ` sashiko-bot
2026-08-21 13:59 ` Guenter Roeck
1 sibling, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-08-21 12:05 UTC (permalink / raw)
To: hanzhijian; +Cc: linux-hwmon
> 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.
>
> Signed-off-by: hanzhijian <hanzhijian1991@gmail.com>
Sashiko has reviewed this patch and found no issues. It looks great!
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260821115703.2017414-1-hanzhijian1991@gmail.com?part=1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] hwmon: (pmbus/ibm-cffps) fix format-truncation warning
2026-08-21 11:57 [PATCH] hwmon: (pmbus/ibm-cffps) fix format-truncation warning hanzhijian
2026-08-21 12:05 ` sashiko-bot
@ 2026-08-21 13:59 ` Guenter Roeck
2026-08-21 14:04 ` hanzhijian
1 sibling, 1 reply; 4+ messages in thread
From: Guenter Roeck @ 2026-08-21 13:59 UTC (permalink / raw)
To: hanzhijian; +Cc: linux-hwmon, linux-kernel
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;
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-08-21 14:04 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-21 11:57 [PATCH] hwmon: (pmbus/ibm-cffps) fix format-truncation warning hanzhijian
2026-08-21 12:05 ` sashiko-bot
2026-08-21 13:59 ` Guenter Roeck
2026-08-21 14:04 ` hanzhijian
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox