hwmon: pmbus: ibm-cffps: avoid format truncation warnings
PATCH 1/1 hwmon: pmbus: ibm-cffps: avoid format truncation warnings
Building with W=1 reports format truncation warnings when formatting the firmware version values for debugfs.
The SMBus helpers return the byte and word values as int, so the compiler cannot infer that the formatted values fit into the small temporary buffers. Cast the values to u8 and u16 before formatting them.
This avoids the -Wformat-truncation warnings while keeping the existing output format unchanged.
--- drivers/hwmon/pmbus/ibm-cffps.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/hwmon/pmbus/ibm-cffps.c +2 -2
@@ -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" , (u8 )rc); } 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" , (u16 )rc); } rc = i *4 ;
Signature · 1 line
2.55.0
[email protected]
AI reviewSashiko has reviewed this patch and found no issues. It looks great!
Quoted 8 lines
Building with W=1 reports format truncation warnings when formatting the firmware version values for debugfs.
The SMBus helpers return the byte and word values as int, so the compiler cannot infer that the formatted values fit into the small temporary buffers. Cast the values to u8 and u16 before formatting them.
Quoted 4 lines
This avoids the -Wformat-truncation warnings while keeping the existing output format unchanged.
Signed-off-by Eduard Zateev <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 8 lines · Eduard Zateev
Building with W=1 reports format truncation warnings when formatting the firmware version values for debugfs.
The SMBus helpers return the byte and word values as int, so the compiler cannot infer that the formatted values fit into the small temporary buffers. Cast the values to u8 and u16 before formatting them.
Quoted 4 lines
This avoids the -Wformat-truncation warnings while keeping the existing output format unchanged.
Signed-off-by Eduard Zateev <[email protected]>
Applied.
Thanks,
Guenter