* [PATCH net] net: thunderx: Fix format-truncation warning in bgx_acpi_match_id()
@ 2025-07-06 19:51 Alok Tiwari
2025-07-07 19:16 ` Simon Horman
0 siblings, 1 reply; 4+ messages in thread
From: Alok Tiwari @ 2025-07-06 19:51 UTC (permalink / raw)
To: sgoutham, andrew+netdev, davem, edumazet, kuba, pabeni, horms,
netdev
Cc: alok.a.tiwari, linux-arm-kernel, darren.kenny, linux-kernel
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@oracle.com>
---
drivers/net/ethernet/cavium/thunder/thunder_bgx.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
index 3b7ad744b2dd6..2eea3142eebea 100644
--- a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
+++ b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
@@ -1429,9 +1429,9 @@ static acpi_status bgx_acpi_match_id(acpi_handle handle, u32 lvl,
{
struct acpi_buffer string = { ACPI_ALLOCATE_BUFFER, NULL };
struct bgx *bgx = context;
- char bgx_sel[5];
+ char bgx_sel[8];
- snprintf(bgx_sel, 5, "BGX%d", bgx->bgx_id);
+ snprintf(bgx_sel, sizeof(bgx_sel), "BGX%d", bgx->bgx_id);
if (ACPI_FAILURE(acpi_get_name(handle, ACPI_SINGLE_NAME, &string))) {
pr_warn("Invalid link device\n");
return AE_OK;
--
2.46.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net] net: thunderx: Fix format-truncation warning in bgx_acpi_match_id()
2025-07-06 19:51 [PATCH net] net: thunderx: Fix format-truncation warning in bgx_acpi_match_id() Alok Tiwari
@ 2025-07-07 19:16 ` Simon Horman
2025-07-08 3:04 ` [External] : " ALOK TIWARI
0 siblings, 1 reply; 4+ messages in thread
From: Simon Horman @ 2025-07-07 19:16 UTC (permalink / raw)
To: Alok Tiwari
Cc: sgoutham, andrew+netdev, davem, edumazet, kuba, pabeni, netdev,
linux-arm-kernel, darren.kenny, linux-kernel
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@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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [External] : Re: [PATCH net] net: thunderx: Fix format-truncation warning in bgx_acpi_match_id()
2025-07-07 19:16 ` Simon Horman
@ 2025-07-08 3:04 ` ALOK TIWARI
2025-07-08 16:09 ` Simon Horman
0 siblings, 1 reply; 4+ messages in thread
From: ALOK TIWARI @ 2025-07-08 3:04 UTC (permalink / raw)
To: Simon Horman
Cc: sgoutham, andrew+netdev, davem, edumazet, kuba, pabeni, netdev,
linux-arm-kernel, darren.kenny, linux-kernel
On 7/8/2025 12:46 AM, Simon Horman wrote:
>> 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@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.
Thanks Simon,
It is compile warning, We can target it for net-next.
I will resend it with [PATCH net-next]
Thanks,
Alok
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [External] : Re: [PATCH net] net: thunderx: Fix format-truncation warning in bgx_acpi_match_id()
2025-07-08 3:04 ` [External] : " ALOK TIWARI
@ 2025-07-08 16:09 ` Simon Horman
0 siblings, 0 replies; 4+ messages in thread
From: Simon Horman @ 2025-07-08 16:09 UTC (permalink / raw)
To: ALOK TIWARI
Cc: sgoutham, andrew+netdev, davem, edumazet, kuba, pabeni, netdev,
linux-arm-kernel, darren.kenny, linux-kernel
On Tue, Jul 08, 2025 at 08:34:39AM +0530, ALOK TIWARI wrote:
>
>
> On 7/8/2025 12:46 AM, Simon Horman wrote:
> > > 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@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.
>
> Thanks Simon,
> It is compile warning, We can target it for net-next.
>
> I will resend it with [PATCH net-next]
Thanks, good plan.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-07-08 16:10 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-06 19:51 [PATCH net] net: thunderx: Fix format-truncation warning in bgx_acpi_match_id() Alok Tiwari
2025-07-07 19:16 ` Simon Horman
2025-07-08 3:04 ` [External] : " ALOK TIWARI
2025-07-08 16:09 ` Simon Horman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).