Skip to contentSkip to conversation

hwmon: pmbus: ibm-cffps: avoid format truncation warnings

PATCH Applied Eduard Zateev 3 participants 3 messages Sep 23 – Sep 24 Hardware monitoring

lore
Share & tools
lore
#0 lore raw

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
index aad94bcb9ceb..2498c6f4778e 100644
@@ -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
#1 lore raw
Sashiko 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.

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
maintainer Applied
#2 lore raw
In reply to Eduard Zateev
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.

Applied.

Thanks,
Guenter