From: David Laight <david.laight.linux@gmail.com>
To: Thorsten Blum <thorsten.blum@linux.dev>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>,
Michael Ellerman <mpe@ellerman.id.au>,
Nicholas Piggin <npiggin@gmail.com>,
"Christophe Leroy (CS GROUP)" <chleroy@kernel.org>,
linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] powerpc/dt_cpu_ftrs: Avoid separate strlen() in scan_callback()
Date: Tue, 30 Jun 2026 18:38:10 +0100 [thread overview]
Message-ID: <20260630183810.3287d10d@pumpkin> (raw)
In-Reply-To: <20260630154657.693088-2-thorsten.blum@linux.dev>
On Tue, 30 Jun 2026 17:46:56 +0200
Thorsten Blum <thorsten.blum@linux.dev> wrote:
> Use the return value of strscpy() when copying the display name instead
> of checking the source string length with strlen() first.
>
> Keep dt_cpu_name static but move it into dt_cpu_ftrs_scan_callback(),
> where it is assigned.
>
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
> arch/powerpc/kernel/dt_cpu_ftrs.c | 7 ++-----
> 1 file changed, 2 insertions(+), 5 deletions(-)
>
> diff --git a/arch/powerpc/kernel/dt_cpu_ftrs.c b/arch/powerpc/kernel/dt_cpu_ftrs.c
> index 3af6c06af02f..8d8e94e4d2bc 100644
> --- a/arch/powerpc/kernel/dt_cpu_ftrs.c
> +++ b/arch/powerpc/kernel/dt_cpu_ftrs.c
> @@ -90,8 +90,6 @@ static void __restore_cpu_cpufeatures(void)
> init_pmu_registers();
> }
>
> -static char dt_cpu_name[64];
> -
> static struct cpu_spec __initdata base_cpu_spec = {
> .cpu_name = NULL,
> .cpu_features = CPU_FTRS_DT_CPU_BASE,
> @@ -1069,6 +1067,7 @@ static int __init count_cpufeatures_subnodes(unsigned long node,
> static int __init dt_cpu_ftrs_scan_callback(unsigned long node, const char
> *uname, int depth, void *data)
> {
> + static char dt_cpu_name[64];
> const __be32 *prop;
> int count, i;
> u32 isa;
> @@ -1106,10 +1105,8 @@ static int __init dt_cpu_ftrs_scan_callback(unsigned long node, const char
> }
>
> prop = of_get_flat_dt_prop(node, "display-name", NULL);
> - if (prop && strlen((char *)prop) != 0) {
> - strscpy(dt_cpu_name, (char *)prop, sizeof(dt_cpu_name));
> + if (prop && strscpy(dt_cpu_name, (char *)prop) != 0)
That is different code.
The old code only did the copy if the new string was non-empty.
So you want to replace the strlen() with *(char *)prop != 0.
Checks for strlen() == 0 are silly (but surprisingly common).
A search might show up this gem:
str[strlen(str)] = 0;
-- David
> cur_cpu_spec->cpu_name = dt_cpu_name;
> - }
>
> cpufeatures_setup_finished();
>
>
next prev parent reply other threads:[~2026-07-01 9:42 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-30 15:46 [PATCH] powerpc/dt_cpu_ftrs: Avoid separate strlen() in scan_callback() Thorsten Blum
2026-06-30 17:38 ` David Laight [this message]
2026-07-01 11:48 ` Thorsten Blum
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=20260630183810.3287d10d@pumpkin \
--to=david.laight.linux@gmail.com \
--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 \
--cc=thorsten.blum@linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.