net: ethernet: freescale: fix false-positive string overflow warning
commit3ded9f2b35f02ca00523c79f88f6cf5050622384
authorArnd Bergmann <arnd@arndb.de>
Mon, 28 May 2018 15:49:46 +0000 (28 17:49 +0200)
committerDavid S. Miller <davem@davemloft.net>
Wed, 30 May 2018 17:16:44 +0000 (30 13:16 -0400)
tree61a95814c11a2bf1efefac10891d04591d8e5a6c
parentae40832e53c33fab2755571dabc1378117bc50d4
net: ethernet: freescale: fix false-positive string overflow warning

While compile-testing on arm64 with gcc-8.1, I ran into a build diagnostic:

drivers/net/ethernet/freescale/fec_main.c: In function 'fec_probe':
drivers/net/ethernet/freescale/fec_main.c:3517:25: error: '%d' directive writing between 1 and 10 bytes into a region of size 5 [-Werror=format-overflow=]
   sprintf(irq_name, "int%d", i);
                         ^~
drivers/net/ethernet/freescale/fec_main.c:3517:21: note: directive argument in the range [0, 2147483646]
   sprintf(irq_name, "int%d", i);
                     ^~~~~~~
drivers/net/ethernet/freescale/fec_main.c:3517:3: note: 'sprintf' output between 5 and 14 bytes into a destination of size 8
   sprintf(irq_name, "int%d", i);
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

It appears this has never shown on ppc32 or arm32 for an unknown reason, but
now gcc fails to identify that the 'irq_cnt' loop index has an upper bound
of 3, and instead uses a bogus range.

To work around the warning, this changes the sprintf to snprintf with the
correct buffer length.

Fixes: 78cc6e7ef957 ("net: ethernet: freescale: Allow FEC with COMPILE_TEST")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Fugang Duan <fugang.duan@nxp.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/freescale/fec_main.c