LinuxPPC-Dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Thorsten Blum <thorsten.blum@linux.dev>
To: Madhavan Srinivasan <maddy@linux.ibm.com>,
	Michael Ellerman <mpe@ellerman.id.au>,
	Nicholas Piggin <npiggin@gmail.com>,
	"Christophe Leroy (CS GROUP)" <chleroy@kernel.org>
Cc: Thorsten Blum <thorsten.blum@linux.dev>,
	linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org
Subject: [PATCH] powerpc: replace strlcat to simplify ppc_kallsyms_lookup_name
Date: Mon,  8 Jun 2026 21:32:03 +0200	[thread overview]
Message-ID: <20260608193203.163266-2-thorsten.blum@linux.dev> (raw)

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)


             reply	other threads:[~2026-06-08 19:32 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-08 19:32 Thorsten Blum [this message]
2026-06-09  4:52 ` [PATCH] powerpc: replace strlcat to simplify ppc_kallsyms_lookup_name Christophe Leroy (CS GROUP)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260608193203.163266-2-thorsten.blum@linux.dev \
    --to=thorsten.blum@linux.dev \
    --cc=chleroy@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=maddy@linux.ibm.com \
    --cc=mpe@ellerman.id.au \
    --cc=npiggin@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox