prestera_dl_info_get() formats the firmware revision with snprintf(buf, sizeof(buf), "%d.%d.%d", sw->dev->fw_rev.maj, sw->dev->fw_rev.min, sw->dev->fw_rev.sub); into a 16 byte buffer. The three fields are u16, so each can print up to five digits and the format can produce 18 bytes including the terminator. gcc reports this in a W=1 build, and CONFIG_WERROR turns the warning into a build failure: drivers/net/ethernet/marvell/prestera/prestera_devlink.c:359:43: error: '%d' directive output may be truncated writing between 1 and 5 bytes into a region of size between 4 and 12 [-Werror=format-truncation=] The values come from the device firmware and are small in practice, but gcc analyses the full u16 range. Size the buffer for the widest string the format allows, "65535.65535.65535", so that the reported version can never be cut. No functional change for the versions seen in practice. Reported-by: kernel test robot Closes: https://lore.kernel.org/r/202501110646.aGxZ97Ug-lkp@intel.com/ Signed-off-by: Aibing Chen --- drivers/net/ethernet/marvell/prestera/prestera_devlink.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/marvell/prestera/prestera_devlink.c b/drivers/net/ethernet/marvell/prestera/prestera_devlink.c index 33dea101b..d5a04a4bb 100644 --- a/drivers/net/ethernet/marvell/prestera/prestera_devlink.c +++ b/drivers/net/ethernet/marvell/prestera/prestera_devlink.c @@ -354,7 +354,7 @@ static int prestera_dl_info_get(struct devlink *dl, struct netlink_ext_ack *extack) { struct prestera_switch *sw = devlink_priv(dl); - char buf[16]; + char buf[sizeof("65535.65535.65535")]; snprintf(buf, sizeof(buf), "%d.%d.%d", sw->dev->fw_rev.maj,