get_drvinfo() formats the firmware and TP revisions into
info->fw_version, a fixed ETHTOOL_FWVERS_LEN (32) byte field of the
ethtool_drvinfo UAPI structure:
snprintf(info->fw_version, sizeof(info->fw_version),
"%u.%u.%u.%u, TP %u.%u.%u.%u", ...);
The eight values are u8, so the format can produce up to 35 bytes; gcc
reports it in a W=1 build and CONFIG_WERROR turns it into a build
failure:
cxgb4_ethtool.c:209:52: error: '%u' directive output may be truncated
writing between 1 and 3 bytes into a region of size between 0 and 14
[-Werror=format-truncation=]
Use scnprintf(), which returns the number of bytes written, so the string
is bounded by the field and the intent is visible at the call site. The
ethtool_drvinfo layout is part of the UAPI and cannot be enlarged.
Reported-by: kernel test robot <l…@intel.com>
Link: https://lore.kernel.org/oe-kbuild-all/2026…@intel.com/
Signed-off-by: Aibing Chen <chen…@cmss.chinamobile.com>
---
drivers/net/ethernet/chelsio/cxgb4/cxgb4_ethtool.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_ethtool.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_ethtool.c
index 0092bc16f..bba9ca03e 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_ethtool.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_ethtool.c
@@ -205,8 +205,8 @@ static void get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
info->regdump_len = get_regs_len(dev);
if (adapter->params.fw_vers)
- snprintf(info->fw_version, sizeof(info->fw_version),
- "%u.%u.%u.%u, TP %u.%u.%u.%u",
+ scnprintf(info->fw_version, sizeof(info->fw_version),
+ "%u.%u.%u.%u, TP %u.%u.%u.%u",
FW_HDR_FW_VER_MAJOR_G(adapter->params.fw_vers),
FW_HDR_FW_VER_MINOR_G(adapter->params.fw_vers),
FW_HDR_FW_VER_MICRO_G(adapter->params.fw_vers),
[PATCH net-next v2 2/2] cxgb4: use scnprintf() for fw_version
- From
- chen…@cmss.chinamobile.com (Aibing Chen)
- Organization
- Usenet Network
- Message-ID
- <2026…@cmss.chinamobile.com>
- Date
- Newsgroups
- linux.kernel.netdev