From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-182.mta0.migadu.com (out-182.mta0.migadu.com [91.218.175.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 43BF5314D1A for ; Wed, 1 Jul 2026 11:48:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782906504; cv=none; b=N/FirsdfdcZcGMJAfkhvcIheleA/6ITUf6bzTLnYYFadVkcxVrjFJxd9kOFUrO550aAO06IvyyKFbr0wTXGH3NoOewVhz3YBmIl8kFckw2dtUn5fDseUBAMgNgmZpRua3QBLMwkV7OHk0VrZDmZ3Zzr8nZhA21TJShox19VDXqI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782906504; c=relaxed/simple; bh=Z30NQUlqcfjlQXU0LoTz18xd19oEgfzLooyUbqjHn1M=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=MRygL/isIsgQ7RkoQVQ1VCCpoYIjFBLX89oHJbKlBsQloaRKGPoXw9a+vx8/HWMqDO8BpSPbSezFQvE1zlQSUGvjDks7gJqNVoPCdC9mMgKdeNuOVoVWwDg+H/RlTAf5886VnftysXG+vlr42Hk1H2AqH2QFT+GeWfje8sS6iZE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=to89oPCv; arc=none smtp.client-ip=91.218.175.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="to89oPCv" Date: Wed, 1 Jul 2026 13:48:11 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1782906500; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=fsn8xJw2RfhnuoUr+P1qk0Nf9Ixprgz1x0gAk3OjnmM=; b=to89oPCvTs9b+J06ANvzqIuW7/8gu2XKrpHMvgUYauEd4/CQeeXh827Yj9ELIA8RRcI9vf oUt9E9vMauYFkDhD7lv/h0dsn8Cs96qrc9FUu+LAHzbJOu/Vwogl4wtv6zMZ6FMjDllJqq +gtdNEKBpS3GrKXO+X6lTkgQqWMcc3k= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Thorsten Blum To: David Laight Cc: Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , "Christophe Leroy (CS GROUP)" , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] powerpc/dt_cpu_ftrs: Avoid separate strlen() in scan_callback() Message-ID: References: <20260630154657.693088-2-thorsten.blum@linux.dev> <20260630183810.3287d10d@pumpkin> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260630183810.3287d10d@pumpkin> X-Migadu-Flow: FLOW_OUT On Tue, Jun 30, 2026 at 06:38:10PM +0100, David Laight wrote: > On Tue, 30 Jun 2026 17:46:56 +0200 > Thorsten Blum 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 > > --- > > 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. Good catch, thanks! I just sent a v2: https://lore.kernel.org/lkml/20260701114428.818748-3-thorsten.blum@linux.dev/