linux/drivers/net/ethernet/marvell/octeontx2/af
Simon Horman 9312ee7649 octeontx2-af: use unsigned int as iterator for unsigned values
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>
Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>
Link: https://patch.msgid.link/20250724-octeontx2-af-unsigned-v1-1-c745c106e06f@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2025-07-25 11:30:50 -07:00
..
cn20k
cgx.c octeontx2-af: use unsigned int as iterator for unsigned values 2025-07-25 11:30:50 -07:00
cgx.h Octeontx2-pf: ethtool: support multi advertise mode 2025-06-27 16:55:59 -07:00
cgx_fw_if.h Octeontx2-af: Introduce mode group index 2025-06-27 16:55:59 -07:00
common.h
lmac_common.h
Makefile
mbox.c
mbox.h Octeontx2-af: Debugfs support for firmware data 2025-07-22 15:36:39 +02:00
mcs.c
mcs.h
mcs_cnf10kb.c
mcs_reg.h
mcs_rvu_if.c
npc.h
npc_profile.h
ptp.c
ptp.h
rpm.c
rpm.h
rvu.c octeontx2-af: Fix error code in rvu_mbox_init() 2025-06-29 10:34:20 +01:00
rvu.h
rvu_cgx.c Octeontx2-af: Add programmed macaddr to RVU pfvf 2025-07-22 15:36:39 +02:00
rvu_cn10k.c net: Fix typos 2025-07-25 10:29:07 -07:00
rvu_cpt.c
rvu_debugfs.c Octeontx2-af: Debugfs support for firmware data 2025-07-22 15:36:39 +02:00
rvu_devlink.c
rvu_devlink.h
rvu_nix.c net: Fix typos 2025-07-25 10:29:07 -07:00
rvu_npa.c
rvu_npc.c
rvu_npc_fs.c
rvu_npc_fs.h
rvu_npc_hash.c
rvu_npc_hash.h
rvu_reg.c
rvu_reg.h
rvu_rep.c
rvu_sdp.c
rvu_struct.h
rvu_switch.c
rvu_trace.c
rvu_trace.h