[PATCH net-next v2] net: thunderx: Fix format-truncation warning in bgx_acpi_match_id()
ALOK TIWARI
alok.a.tiwari at oracle.com
Fri Jul 11 03:17:43 PDT 2025
On 7/11/2025 4:04 AM, Jakub Kicinski wrote:
> On Tue, 8 Jul 2025 10:52:43 -0700 Alok Tiwari wrote:
>> 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);
>
> Hm, why are you making it 8 when the max length is 7 ? 🤔️
yes, 7 is max range. I will send v3 with this change.
Thanks,
Alok
More information about the linux-arm-kernel
mailing list