Netdev List
 help / color / mirror / Atom feed
From: Aibing Chen <chenaibing@cmss.chinamobile.com>
To: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH net-next v2 2/2] cxgb4: use scnprintf() for fw_version
Date: Fri,  4 Dec 2026 17:48:16 +0800	[thread overview]
Message-ID: <20261204094816.116-2-chenaibing@cmss.chinamobile.com> (raw)
In-Reply-To: <20261204094816.116-1-chenaibing@cmss.chinamobile.com>

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 <lkp@intel.com>
Link: https://lore.kernel.org/oe-kbuild-all/202604141419.a4vuNBN7-lkp@intel.com/
Signed-off-by: Aibing Chen <chenaibing@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),



      reply	other threads:[~2026-12-04  9:48 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04  9:48 [PATCH net-next v2 1/2] cxgb4: size the MSI-X interrupt name buffer Aibing Chen
2026-12-04  9:48 ` Aibing Chen [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261204094816.116-2-chenaibing@cmss.chinamobile.com \
    --to=chenaibing@cmss.chinamobile.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=willemdebruijn.kernel@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox