Skip to content

Commit 08e2153

Browse files
tobluxakpm00
authored andcommitted
alpha: replace sprintf()/strcpy() with scnprintf()/strscpy()
Replace sprintf() with the safer variant scnprintf() and use its return value instead of calculating the string length again using strlen(). Use strscpy() instead of the deprecated strcpy(). No functional changes intended. Link: KSPP#88 Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Thorsten Blum <[email protected]> Cc: Alexander Gordeev <[email protected]> Cc: Geert Uytterhoeven <[email protected]> Cc: guoweikang <[email protected]> Cc: Matt Turner <[email protected]> Cc: Mike Rapoport <[email protected]> Cc: Richard Henderson <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 85df0d5 commit 08e2153

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

arch/alpha/kernel/core_marvel.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <linux/vmalloc.h>
1818
#include <linux/mc146818rtc.h>
1919
#include <linux/rtc.h>
20+
#include <linux/string.h>
2021
#include <linux/module.h>
2122
#include <linux/memblock.h>
2223

@@ -79,10 +80,12 @@ mk_resource_name(int pe, int port, char *str)
7980
{
8081
char tmp[80];
8182
char *name;
82-
83-
sprintf(tmp, "PCI %s PE %d PORT %d", str, pe, port);
84-
name = memblock_alloc_or_panic(strlen(tmp) + 1, SMP_CACHE_BYTES);
85-
strcpy(name, tmp);
83+
size_t sz;
84+
85+
sz = scnprintf(tmp, sizeof(tmp), "PCI %s PE %d PORT %d", str, pe, port);
86+
sz += 1; /* NUL terminator */
87+
name = memblock_alloc_or_panic(sz, SMP_CACHE_BYTES);
88+
strscpy(name, tmp, sz);
8689

8790
return name;
8891
}

0 commit comments

Comments
 (0)