Skip to contentSkip to conversation

usbip: vhci: fix -Wformat-truncation warning in vhci_sysfs

PATCH New Ricardo Barbosa Dias 1 participant 1 message Sep 13

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usbip: vhci: fix -Wformat-truncation warning in vhci_sysfs

Fix a compilation warning reported by GCC when building with W=1:

drivers/usb/usbip/vhci_sysfs.c:474:67: error: '%d' directive output may be truncated writing between 1 and 11 bytes into a region of size 10 [-Werror=format-truncation=]

Although vhci_num_controllers is bounded between 1 and 32 in Kconfig, the compiler performs static analysis considering the full range of a signed integer.

Increase MAX_STATUS_NAME in vhci.h to 18 to ensure the buffer char array can accommodate the theoretical maximum length of formatted status names, silencing the format-truncation warning.

---
 drivers/usb/usbip/vhci.h       | 2 +-
 drivers/usb/usbip/vhci_sysfs.c | 2 --
 2 files changed, 1 insertion(+), 3 deletions(-)
drivers/usb/usbip/vhci.h +1 -1
index 5659dce15..2c09fcb61 100644
@@ -88,7 +88,7 @@ enum hub_speed {
 #define VHCI_NR_HCS 1
 #endif
 
-#define MAX_STATUS_NAME 16
+#define MAX_STATUS_NAME 18
 
 struct vhci {
 	spinlock_t lock;
drivers/usb/usbip/vhci_sysfs.c +0 -2
index a7ede6fb3..d870e2c27 100644
@@ -454,8 +454,6 @@ static ssize_t attach_store(struct device *dev, struct device_attribute *attr,
 }
 static DEVICE_ATTR_WO(attach);
 
-#define MAX_STATUS_NAME 16
-
 struct status_attr {
 	struct device_attribute attr;
 	char name[MAX_STATUS_NAME+1];
Signature · 1 line
2.43.0