From: Vadim Fedorenko <vadim.fedorenko@linux.dev>
To: Simon Horman <horms@kernel.org>,
Sunil Goutham <sgoutham@marvell.com>,
Linu Cherian <lcherian@marvell.com>,
Geetha sowjanya <gakula@marvell.com>,
Jerin Jacob <jerinj@marvell.com>, hariprasad <hkelam@marvell.com>,
Subbaraya Sundeep <sbhatta@marvell.com>
Cc: Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
netdev@vger.kernel.org
Subject: Re: [PATCH net-next] octeontx2-af: use unsigned int as iterator for unsigned values
Date: Thu, 24 Jul 2025 14:25:21 +0100 [thread overview]
Message-ID: <5a716f1d-5a37-4634-be93-ba37b3b817c5@linux.dev> (raw)
In-Reply-To: <20250724-octeontx2-af-unsigned-v1-1-c745c106e06f@kernel.org>
On 24/07/2025 14:10, Simon Horman wrote:
> The local variable i is used to iterate over unsigned
> values. The lower bound of the loop is set to 0. While
> the upper bound is cgx->lmac_count, where they lmac_count is
> an u8. So the theoretical upper bound is 255.
>
> As is, GCC can't see this range of values and warns that
> a formatted string, which includes the %d representation of i,
> may overflow the buffer provided.
>
> GCC 15.1.0 says:
>
> .../cgx.c: In function 'cgx_lmac_init':
> .../cgx.c:1737:49: warning: '%d' directive writing between 1 and 11 bytes into a region of size between 4 and 6 [-Wformat-overflow=]
> 1737 | sprintf(lmac->name, "cgx_fwi_%d_%d", cgx->cgx_id, i);
> | ^~
> .../cgx.c:1737:37: note: directive argument in the range [-2147483641, 254]
> 1737 | sprintf(lmac->name, "cgx_fwi_%d_%d", cgx->cgx_id, i);
> | ^~~~~~~~~~~~~~~
> .../cgx.c:1737:17: note: 'sprintf' output between 12 and 24 bytes into a destination of size 16
> 1737 | sprintf(lmac->name, "cgx_fwi_%d_%d", cgx->cgx_id, i);
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> Empirically, changing the type of i from (signed) int to unsigned int
> addresses this problem. I assume by allowing GCC to see the range of
> values described above.
>
> Also update the format specifiers for the integer values in the string
> in question from %d to %u. This seems appropriate as they are now both
> unsigned.
>
> No functional change intended.
> Compile tested only.
>
> Signed-off-by: Simon Horman <horms@kernel.org>
> ---
> drivers/net/ethernet/marvell/octeontx2/af/cgx.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>
next prev parent reply other threads:[~2025-07-24 13:25 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-24 13:10 [PATCH net-next] octeontx2-af: use unsigned int as iterator for unsigned values Simon Horman
2025-07-24 13:25 ` Vadim Fedorenko [this message]
2025-07-25 18:40 ` patchwork-bot+netdevbpf
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=5a716f1d-5a37-4634-be93-ba37b3b817c5@linux.dev \
--to=vadim.fedorenko@linux.dev \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=gakula@marvell.com \
--cc=hkelam@marvell.com \
--cc=horms@kernel.org \
--cc=jerinj@marvell.com \
--cc=kuba@kernel.org \
--cc=lcherian@marvell.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sbhatta@marvell.com \
--cc=sgoutham@marvell.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.