Skip to contentSkip to conversation

perf tools: Replace strlcpy with strscpy

PATCH In review ny 2 participants 2 messages Dec 9, 2025 – Jan 13 perf events

lore
Share & tools
lore

ny

author
#0 lore raw

PATCH 1/1 perf tools: Replace strlcpy with strscpy

Replace the deprecated strlcpy function with the preferred strscpy function in tools/perf/util/machine.c.

strlcpy is deprecated and should be replaced with strscpy according to kernel best practices. The strscpy function is safer and is the recommended replacement.

---
 tools/perf/util/machine.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/machine.c +1 -1
index 841b711d9..8786764e2 100644
@@ -1052,7 +1052,7 @@ int machine__create_extra_kernel_map(struct machine *machine,
 
 	kmap = map__kmap(map);
 
-	strlcpy(kmap->name, xm->name, KMAP_NAME_LEN);
+	strscpy(kmap->name, xm->name, KMAP_NAME_LEN);
 
 	err = maps__insert(machine__kernel_maps(machine), map);
 
Signature · 1 line
2.43.0
#1 lore raw
Quoted 6 lines · ny

Replace the deprecated strlcpy function with the preferred strscpy function in tools/perf/util/machine.c.

strlcpy is deprecated and should be replaced with strscpy according to kernel best practices. The strscpy function is safer and is the recommended replacement.

Take a look at this:

acme@number:~/git/perf-tools-next$ git grep strscpy tools/
tools/include/linux/string.h:#define strscpy strcpy
tools/testing/selftests/net/ovpn/ovpn-cli.c:#define strscpy strncpy
tools/testing/selftests/net/ovpn/ovpn-cli.c:    strscpy(ovpn->ifname, argv[2], IFNAMSIZ - 1);
tools/testing/selftests/user_events/abi_test.c:                         /* strscpy is not available, use snprintf */
acme@number:~/git/perf-tools-next$

:-)

srcscpy() thus seems to be only available in the kernel sources, not for tools/, that would be another project.

- Arnaldo

Quoted 20 lines
---
 tools/perf/util/machine.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/machine.c +1 -1
index 841b711d9..8786764e2 100644
@@ -1052,7 +1052,7 @@ int machine__create_extra_kernel_map(struct machine *machine,
 
 	kmap = map__kmap(map);
 
-	strlcpy(kmap->name, xm->name, KMAP_NAME_LEN);
+	strscpy(kmap->name, xm->name, KMAP_NAME_LEN);
 
 	err = maps__insert(machine__kernel_maps(machine), map);
 
Signature · 1 line
2.43.0