* [PATCH net-next v2 1/2] cxgb4: size the MSI-X interrupt name buffer
@ 2026-12-04 9:48 Aibing Chen
2026-12-04 9:48 ` [PATCH net-next v2 2/2] cxgb4: use scnprintf() for fw_version Aibing Chen
2026-12-05 10:04 ` [PATCH net-next v2 1/2] cxgb4: size the MSI-X interrupt name buffer netdev-bot+sashiko
0 siblings, 2 replies; 4+ messages in thread
From: Aibing Chen @ 2026-12-04 9:48 UTC (permalink / raw)
To: Willem de Bruijn; +Cc: netdev, linux-kernel
The MSI-X interrupt names are assembled with snprintf() into
adap->msix_info[].desc[IFNAMSIZ + 10], from adap->port[0]->name (up to
IFNAMSIZ - 1 characters) plus a suffix and a queue index:
"%s-Rx%d" needs IFNAMSIZ - 1 + 3 + 5 + 1 = 24 bytes
"%s-mirrorrxq%d" needs IFNAMSIZ - 1 + 10 + 5 + 1 = 31 bytes
"%s-%s%d" needs 2 * (IFNAMSIZ - 1) + 1 + 11 + 1 = 43 bytes
The last one also formats the ULD queue name, which is copied from the
ULD with memcpy(rxq_info->name, uld_info->name, IFNAMSIZ) into a
char[IFNAMSIZ] field, so it can be up to IFNAMSIZ - 1 characters as well.
Because -Wformat-truncation is enabled for W=1 builds and COMPILE_TEST
configurations turn it into an error through CONFIG_WERROR, the driver
does not build today:
cxgb4_main.c:1074:48: error: '%d' directive output may be truncated
writing between 1 and 11 bytes into a region of size between 8 and 23
[-Werror=format-truncation=]
cxgb4_main.c:1356:47: error: '%d' directive output may be truncated
writing between 1 and 5 bytes into a region of size between 1 and 16
cxgb4_uld.c:141:38: error: '%s' directive output may be truncated
writing up to 15 bytes into a region of size between 10 and 25
Size desc[] for the worst case, 2 * IFNAMSIZ + 11 bytes, so that the
size tracks IFNAMSIZ.
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.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4.h b/drivers/net/ethernet/chelsio/cxgb4/cxgb4.h
index f20f4bc58..fe5f6af9c 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4.h
+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4.h
@@ -1049,7 +1049,7 @@ struct msix_bmap {
struct msix_info {
unsigned short vec;
- char desc[IFNAMSIZ + 10];
+ char desc[2 * IFNAMSIZ + 11];
unsigned int idx;
cpumask_var_t aff_mask;
};
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH net-next v2 2/2] cxgb4: use scnprintf() for fw_version 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 2026-12-05 10:04 ` netdev-bot+sashiko 2026-12-05 10:04 ` [PATCH net-next v2 1/2] cxgb4: size the MSI-X interrupt name buffer netdev-bot+sashiko 1 sibling, 1 reply; 4+ messages in thread From: Aibing Chen @ 2026-12-04 9:48 UTC (permalink / raw) To: Willem de Bruijn; +Cc: netdev, linux-kernel 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), ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net-next v2 2/2] cxgb4: use scnprintf() for fw_version 2026-12-04 9:48 ` [PATCH net-next v2 2/2] cxgb4: use scnprintf() for fw_version Aibing Chen @ 2026-12-05 10:04 ` netdev-bot+sashiko 0 siblings, 0 replies; 4+ messages in thread From: netdev-bot+sashiko @ 2026-12-05 10:04 UTC (permalink / raw) To: chenaibing; +Cc: willemdebruijn.kernel, netdev, linux-kernel, kuba Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider. Critical: 0 · High: 0 · Medium: 1 · Low: 2 (1) If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough). - [Medium] The patch leaves the same construct unfixed in the sibling cxgb4vf driver. - [Low] The commit message misdescribes what the change does. - [Low] The continuation lines of the call are left inconsistently aligned. Pre-existing issues: - [Low] This problem wasn't introduced by this patch, but get_drvinfo() in drivers/net/ethernet/chelsio/cxgb4/cxgb4_ethtool.c can still format… -- cxgb4: use scnprintf() for fw_version This commit changes get_drvinfo() in cxgb4 to format info->fw_version with scnprintf() instead of snprintf(). The goal is to silence a -Wformat-truncation error that the kernel test robot reported for W=1 builds with CONFIG_WERROR. Link: https://lore.kernel.org/oe-kbuild-all/202604141419.a4vuNBN7-lkp@intel.com/ > 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. [Severity: Low] Is this description accurate? snprintf() already limited the string to size - 1 bytes plus a NUL. scnprintf() writes exactly the same bytes and differs only in its return value, which get_drvinfo() discards. The warning seems to go away only because GCC's format-truncation analysis covers the snprintf()/vsnprintf() built-ins. scnprintf() is a plain kernel function declared with __printf(3, 4) in include/linux/sprintf.h, so GCC doesn't check it. The diagnostic was a true positive, since 35 characters can exceed the 31 usable bytes. Could the changelog say that the warning is being suppressed, and that the ", TP ..." suffix can still be truncated? > diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_ethtool.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_ethtool.c > index c72c0bcd45c80..7c88bc8102d7d 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", [Severity: Medium] Does the same build failure still happen in the sibling cxgb4vf driver? cxgb4vf_get_drvinfo() in drivers/net/ethernet/chelsio/cxgb4vf/cxgb4vf_main.c still has the same construct: snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version), "%u.%u.%u.%u, TP %u.%u.%u.%u", FW_HDR_FW_VER_MAJOR_G(adapter->params.dev.fwrev), FW_HDR_FW_VER_MINOR_G(adapter->params.dev.fwrev), FW_HDR_FW_VER_MICRO_G(adapter->params.dev.fwrev), ... It uses the same FW_HDR_FW_VER_*_G() accessors from cxgb4/t4fw_api.h, whose masks are all 0xff. It also writes into the same 32-byte fw_version field, so GCC should compute the same 35-character worst case. scripts/Makefile.warn adds -Wno-format-truncation only outside of W=1. A W=1 build with CONFIG_WERROR (or W=e) and CONFIG_CHELSIO_T4VF enabled, such as allmodconfig, would therefore still fail. The commit message describes this build failure as resolved. Should cxgb4vf be handled in the same patch? [Severity: Low] This isn't a bug introduced by this patch, but get_drvinfo() can still format more characters than info->fw_version can hold. The field is ETHTOOL_FWVERS_LEN (32) bytes. With eight 0xff-masked fields, the worst case is 24 digits + 6 dots + ", TP " = 35 characters. In that case, the TP revision reported by ethtool -i is silently cut, for example "200.100.200.100, TP 200.100.20". The switch to scnprintf() doesn't change where the truncation happens. It only removes the warning that pointed to it. > 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), [Severity: Low] This isn't a bug, but only the format string line was re-indented to match the new scnprintf( parenthesis. The eight FW_HDR_FW_VER_*_G() argument lines keep the old alignment that matched snprintf(, so one call now has mixed continuation indentation. Could these lines be re-aligned too? -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204094816.116-1-chenaibing%40cmss.chinamobile.com ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net-next v2 1/2] cxgb4: size the MSI-X interrupt name buffer 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 ` [PATCH net-next v2 2/2] cxgb4: use scnprintf() for fw_version Aibing Chen @ 2026-12-05 10:04 ` netdev-bot+sashiko 1 sibling, 0 replies; 4+ messages in thread From: netdev-bot+sashiko @ 2026-12-05 10:04 UTC (permalink / raw) To: chenaibing; +Cc: willemdebruijn.kernel, netdev, linux-kernel, kuba Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin. Low priority / nit picks for your consideration: - [Low] The commit message for "cxgb4: size the MSI-X interrupt name buffer" gets some of its arithmetic wrong, and it leaves out a user-… -- cxgb4: size the MSI-X interrupt name buffer This commit grows desc[] in struct msix_info from IFNAMSIZ + 10 to 2 * IFNAMSIZ + 11 bytes. After the change, the snprintf() calls that build MSI-X interrupt names in setup_sge_queues(), cxgb4_port_mirror_alloc_queues() and alloc_uld_rxqs() can no longer truncate. This fixes the -Wformat-truncation errors in W=1 builds with CONFIG_WERROR. Link: https://lore.kernel.org/oe-kbuild-all/202604141419.a4vuNBN7-lkp@intel.com/ > The MSI-X interrupt names are assembled with snprintf() into > adap->msix_info[].desc[IFNAMSIZ + 10], from adap->port[0]->name (up to > IFNAMSIZ - 1 characters) plus a suffix and a queue index: > > "%s-Rx%d" needs IFNAMSIZ - 1 + 3 + 5 + 1 = 24 bytes [Severity: Low] The new size looks right to me, but is the 24 byte figure for "%s-Rx%d" correct? In setup_sge_queues() the queue index is a plain int: int err, i, j, msix = 0; ... snprintf(adap->msix_info[msix].desc, sizeof(adap->msix_info[msix].desc), "%s-Rx%d", dev->name, j); So %d can produce up to 11 characters, and the worst case is 15 + 3 + 11 + 1 = 30 bytes. If the format only needed 24 bytes, it would fit in the old 26 byte desc[] and would not warn. But the first compiler error quoted further down is for this format, and it says: > cxgb4_main.c:1074:48: error: '%d' directive output may be truncated > writing between 1 and 11 bytes into a region of size between 8 and 23 The 5 digit assumption only holds for "%s-mirrorrxq%d", where i is a u16 in cxgb4_port_mirror_alloc_queues(). The changelog also presents this only as a build failure. Doesn't it change runtime behaviour as well? Before this patch, alloc_uld_rxqs() could truncate the name at runtime: snprintf(adap->msix_info[msi_idx].desc, sizeof(adap->msix_info[msi_idx].desc), "%s-%s%d", adap->port[0]->name, rxq_info->name, i); Take a 15 character port name, the "iw_cxgb4" ULD and a two digit queue index. That needs 15 + 1 + 8 + 2 + 1 = 27 bytes, so the old 26 byte buffer cut the name off before it reached request_irq(). With this patch the full name shows up in /proc/interrupts. Could the commit message correct the "%s-Rx%d" arithmetic and mention that some IRQ names in /proc/interrupts will change? -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204094816.116-1-chenaibing%40cmss.chinamobile.com ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-12-05 10:04 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 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 ` [PATCH net-next v2 2/2] cxgb4: use scnprintf() for fw_version Aibing Chen 2026-12-05 10:04 ` netdev-bot+sashiko 2026-12-05 10:04 ` [PATCH net-next v2 1/2] cxgb4: size the MSI-X interrupt name buffer netdev-bot+sashiko
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox