[PATCH net] net: thunderx: Fix format-truncation warning in bgx_acpi_match_id()
Simon Horman
horms at kernel.org
Mon Jul 7 12:16:44 PDT 2025
On Sun, Jul 06, 2025 at 12:51:42PM -0700, Alok Tiwari wrote:
> The buffer bgx_sel used in snprintf() was too small to safely hold
> the formatted string "BGX%d" for all valid bgx_id values. This caused
> a -Wformat-truncation warning with Werror enabled during build.
>
> Increase the buffer size from 5 to 8 and use sizeof(bgx_sel) in
> snprintf() to ensure safety and suppress the warning.
>
> Build warning:
> CC drivers/net/ethernet/cavium/thunder/thunder_bgx.o
> drivers/net/ethernet/cavium/thunder/thunder_bgx.c: In function
> ‘bgx_acpi_match_id’:
> drivers/net/ethernet/cavium/thunder/thunder_bgx.c:1434:27: error: ‘%d’
> directive output may be truncated writing between 1 and 3 bytes into a
> region of size 2 [-Werror=format-truncation=]
> snprintf(bgx_sel, 5, "BGX%d", bgx->bgx_id);
> ^~
> drivers/net/ethernet/cavium/thunder/thunder_bgx.c:1434:23: note:
> directive argument in the range [0, 255]
> snprintf(bgx_sel, 5, "BGX%d", bgx->bgx_id);
> ^~~~~~~
> drivers/net/ethernet/cavium/thunder/thunder_bgx.c:1434:2: note:
> ‘snprintf’ output between 5 and 7 bytes into a destination of size 5
> snprintf(bgx_sel, 5, "BGX%d", bgx->bgx_id);
>
> compiler warning due to insufficient snprintf buffer size.
>
> Signed-off-by: Alok Tiwari <alok.a.tiwari at oracle.com>
Thanks Alok,
I agree this is a good change.
However, by my reading the range of values of bgx->bgx_id is 0 - 8
because of the application of BGX_ID_MASK which restricts the
value to 3 bits.
If so, I don't think this is a bug and it should be targeted at net-next.
With a description of why it is not a bug.
Conversely, you think it is a bug, then I think an explanation as to why
would be nice to add to the commit description. And A fixes tag is needed.
--
pw-bot: changes-requested
More information about the linux-arm-kernel
mailing list