diff mbox series

[net-next,v2] drivers: net: sky2: Fix -Wstringop-truncation with W=1

Message ID 20201110023222.1479398-1-andrew@lunn.ch (mailing list archive)
State Accepted
Delegated to: Netdev Maintainers
Headers show
Series [net-next,v2] drivers: net: sky2: Fix -Wstringop-truncation with W=1 | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for net-next
netdev/subject_prefix success Link
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 17 this patch: 16
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 16 this patch: 16
netdev/header_inline success Link
netdev/stable success Stable not CCed

Commit Message

Andrew Lunn Nov. 10, 2020, 2:32 a.m. UTC
In function ‘strncpy’,
    inlined from ‘sky2_name’ at drivers/net/ethernet/marvell/sky2.c:4903:3,
    inlined from ‘sky2_probe’ at drivers/net/ethernet/marvell/sky2.c:5049:2:
./include/linux/string.h:297:30: warning: ‘__builtin_strncpy’ specified bound 16 equals destination size [-Wstringop-truncation]

None of the device names are 16 characters long, so it was never an
issue. But replace the strncpy with an snprintf() to prevent the
theoretical overflow.

Suggested-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
 drivers/net/ethernet/marvell/sky2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Stephen Hemminger Nov. 10, 2020, 6:06 a.m. UTC | #1
On Tue, 10 Nov 2020 03:32:22 +0100
Andrew Lunn <andrew@lunn.ch> wrote:

> In function ‘strncpy’,
>     inlined from ‘sky2_name’ at drivers/net/ethernet/marvell/sky2.c:4903:3,
>     inlined from ‘sky2_probe’ at drivers/net/ethernet/marvell/sky2.c:5049:2:
> ./include/linux/string.h:297:30: warning: ‘__builtin_strncpy’ specified bound 16 equals destination size [-Wstringop-truncation]
> 
> None of the device names are 16 characters long, so it was never an
> issue. But replace the strncpy with an snprintf() to prevent the
> theoretical overflow.
> 
> Suggested-by: Stephen Hemminger <stephen@networkplumber.org>
> Signed-off-by: Andrew Lunn <andrew@lunn.ch>

Acked-by: Stephen Hemminger <stephen@networkplumber.org>
Jakub Kicinski Nov. 12, 2020, 4:24 a.m. UTC | #2
On Tue, 10 Nov 2020 03:32:22 +0100 Andrew Lunn wrote:
> In function ‘strncpy’,
>     inlined from ‘sky2_name’ at drivers/net/ethernet/marvell/sky2.c:4903:3,
>     inlined from ‘sky2_probe’ at drivers/net/ethernet/marvell/sky2.c:5049:2:
> ./include/linux/string.h:297:30: warning: ‘__builtin_strncpy’ specified bound 16 equals destination size [-Wstringop-truncation]
> 
> None of the device names are 16 characters long, so it was never an
> issue. But replace the strncpy with an snprintf() to prevent the
> theoretical overflow.
> 
> Suggested-by: Stephen Hemminger <stephen@networkplumber.org>
> Signed-off-by: Andrew Lunn <andrew@lunn.ch>

Applied, thanks!
diff mbox series

Patch

diff --git a/drivers/net/ethernet/marvell/sky2.c b/drivers/net/ethernet/marvell/sky2.c
index 25981a7a43b5..ebe1406c6e64 100644
--- a/drivers/net/ethernet/marvell/sky2.c
+++ b/drivers/net/ethernet/marvell/sky2.c
@@ -4900,7 +4900,7 @@  static const char *sky2_name(u8 chipid, char *buf, int sz)
 	};
 
 	if (chipid >= CHIP_ID_YUKON_XL && chipid <= CHIP_ID_YUKON_OP_2)
-		strncpy(buf, name[chipid - CHIP_ID_YUKON_XL], sz);
+		snprintf(buf, sz, "%s", name[chipid - CHIP_ID_YUKON_XL]);
 	else
 		snprintf(buf, sz, "(chip %#x)", chipid);
 	return buf;