* [PATCH] powerpc: replace strlcat to simplify ppc_kallsyms_lookup_name
@ 2026-06-08 19:32 Thorsten Blum
2026-06-09 4:52 ` Christophe Leroy (CS GROUP)
0 siblings, 1 reply; 2+ messages in thread
From: Thorsten Blum @ 2026-06-08 19:32 UTC (permalink / raw)
To: Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy (CS GROUP)
Cc: Thorsten Blum, linuxppc-dev, linux-kernel
strlcat() should not be used anymore (see fortify-string.h), and since
name is guaranteed to be NUL-terminated within KSYM_NAME_LEN bytes, use
memcpy() instead.
Rename dot_appended to the semantically clearer prepend_dot while at it.
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
arch/powerpc/include/asm/text-patching.h | 17 ++++++++---------
1 file changed, 8 insertions(+), 9 deletions(-)
diff --git a/arch/powerpc/include/asm/text-patching.h b/arch/powerpc/include/asm/text-patching.h
index e7f14720f630..c47b813bd067 100644
--- a/arch/powerpc/include/asm/text-patching.h
+++ b/arch/powerpc/include/asm/text-patching.h
@@ -227,22 +227,21 @@ static inline unsigned long ppc_kallsyms_lookup_name(const char *name)
#ifdef CONFIG_PPC64_ELF_ABI_V1
/* check for dot variant */
char dot_name[1 + KSYM_NAME_LEN];
- bool dot_appended = false;
+ bool prepend_dot = name[0] != '.';
+ size_t len = strnlen(name, KSYM_NAME_LEN);
- if (strnlen(name, KSYM_NAME_LEN) >= KSYM_NAME_LEN)
+ if (len == KSYM_NAME_LEN)
return 0;
- if (name[0] != '.') {
+ if (prepend_dot) {
dot_name[0] = '.';
- dot_name[1] = '\0';
- strlcat(dot_name, name, sizeof(dot_name));
- dot_appended = true;
+ memcpy(dot_name + 1, name, len + 1);
} else {
- dot_name[0] = '\0';
- strlcat(dot_name, name, sizeof(dot_name));
+ memcpy(dot_name, name, len + 1);
}
+
addr = kallsyms_lookup_name(dot_name);
- if (!addr && dot_appended)
+ if (!addr && prepend_dot)
/* Let's try the original non-dot symbol lookup */
addr = kallsyms_lookup_name(name);
#elif defined(CONFIG_PPC64_ELF_ABI_V2)
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] powerpc: replace strlcat to simplify ppc_kallsyms_lookup_name
2026-06-08 19:32 [PATCH] powerpc: replace strlcat to simplify ppc_kallsyms_lookup_name Thorsten Blum
@ 2026-06-09 4:52 ` Christophe Leroy (CS GROUP)
0 siblings, 0 replies; 2+ messages in thread
From: Christophe Leroy (CS GROUP) @ 2026-06-09 4:52 UTC (permalink / raw)
To: Thorsten Blum, Madhavan Srinivasan, Michael Ellerman,
Nicholas Piggin
Cc: linuxppc-dev, linux-kernel
Le 08/06/2026 à 21:32, Thorsten Blum a écrit :
> strlcat() should not be used anymore (see fortify-string.h), and since
> name is guaranteed to be NUL-terminated within KSYM_NAME_LEN bytes, use
> memcpy() instead.
>
> Rename dot_appended to the semantically clearer prepend_dot while at it.
>
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Please take
https://patchwork.ozlabs.org/project/linuxppc-dev/patch/20260506021143.13797-1-xieyuanbin1@huawei.com/
instead
Christophe
> ---
> arch/powerpc/include/asm/text-patching.h | 17 ++++++++---------
> 1 file changed, 8 insertions(+), 9 deletions(-)
>
> diff --git a/arch/powerpc/include/asm/text-patching.h b/arch/powerpc/include/asm/text-patching.h
> index e7f14720f630..c47b813bd067 100644
> --- a/arch/powerpc/include/asm/text-patching.h
> +++ b/arch/powerpc/include/asm/text-patching.h
> @@ -227,22 +227,21 @@ static inline unsigned long ppc_kallsyms_lookup_name(const char *name)
> #ifdef CONFIG_PPC64_ELF_ABI_V1
> /* check for dot variant */
> char dot_name[1 + KSYM_NAME_LEN];
> - bool dot_appended = false;
> + bool prepend_dot = name[0] != '.';
> + size_t len = strnlen(name, KSYM_NAME_LEN);
>
> - if (strnlen(name, KSYM_NAME_LEN) >= KSYM_NAME_LEN)
> + if (len == KSYM_NAME_LEN)
> return 0;
>
> - if (name[0] != '.') {
> + if (prepend_dot) {
> dot_name[0] = '.';
> - dot_name[1] = '\0';
> - strlcat(dot_name, name, sizeof(dot_name));
> - dot_appended = true;
> + memcpy(dot_name + 1, name, len + 1);
> } else {
> - dot_name[0] = '\0';
> - strlcat(dot_name, name, sizeof(dot_name));
> + memcpy(dot_name, name, len + 1);
> }
> +
> addr = kallsyms_lookup_name(dot_name);
> - if (!addr && dot_appended)
> + if (!addr && prepend_dot)
> /* Let's try the original non-dot symbol lookup */
> addr = kallsyms_lookup_name(name);
> #elif defined(CONFIG_PPC64_ELF_ABI_V2)
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-06-09 4:52 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-08 19:32 [PATCH] powerpc: replace strlcat to simplify ppc_kallsyms_lookup_name Thorsten Blum
2026-06-09 4:52 ` Christophe Leroy (CS GROUP)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox