From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-186.mta1.migadu.com (out-186.mta1.migadu.com [95.215.58.186]) (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 BC9573F23DF for ; Wed, 1 Jul 2026 11:45:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.186 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782906316; cv=none; b=a9eQ1dBbYEBZw1zXRMKGo9ljwatjdZtkrJuSrLSbbgjKocNRS0GPybNdw0COthXi+VwxBmpLJzVD4PAPpTNO222JERcmYmJ8Mr9/+U0UdYhN0kKN4fb8xcpfPXIw0DZC410IdzaVOUmLSBq3VUH2t10KIRv96fTEJChfgK6+eXM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782906316; c=relaxed/simple; bh=E75/SRsgQeXD7pVj5U+TFWau1RMu0zbCmb7kpJzaYpo=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=AuBlrhLKxzC0j+tA1EECJ9JOtVgHiSpBi3I/6AX2jAqCxZmF4bugvzRuW/0LYdkd0QjTRkbVj5xAWNnUQMi3I/1X1dRvNdIQnbB5F5u44AaBnIl/lqGpXYm/4I9//RXVVTDF44xWjOmvAbU/LK4eUVVq/nTEB2Bgu52jAqtOAoQ= 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; arc=none smtp.client-ip=95.215.58.186 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 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Thorsten Blum To: Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , "Christophe Leroy (CS GROUP)" Cc: David Laight , Thorsten Blum , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] powerpc/dt_cpu_ftrs: Avoid separate strlen() in scan_callback() Date: Wed, 1 Jul 2026 13:44:28 +0200 Message-ID: <20260701114428.818748-3-thorsten.blum@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1679; i=thorsten.blum@linux.dev; h=from:subject; bh=E75/SRsgQeXD7pVj5U+TFWau1RMu0zbCmb7kpJzaYpo=; b=owGbwMvMwCUWt7pQ4caZUj3G02pJDFkuf+cEG21I+POpbXrPvbO7uF2X6ZZmsV60OPBOkp2Bc 7J55VmJjlIWBjEuBlkxRZYHs37M8C2tqdxkErETZg4rE8gQBi5OAbjJxxkZ7gS0vV5i2Gd57+G6 +ceCFyUuN1X4f/pojIu0ep9hR5OaLsP/PEGNRdVyevbCletSTJdunmY4J7Au7kZF/q2rIS+WLBF iBQA= X-Developer-Key: i=thorsten.blum@linux.dev; a=openpgp; fpr=1D60735E8AEF3BE473B69D84733678FD8DFEEAD4 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT Check only the first byte instead of scanning the entire string with strlen(). While at it, keep dt_cpu_name static, but move it into dt_cpu_ftrs_scan_callback(), where it is assigned. Signed-off-by: Thorsten Blum --- Changes in v2: - Check only the first byte since strscpy() copies empty strings (David) - v1: https://lore.kernel.org/lkml/20260630154657.693088-2-thorsten.blum@linux.dev/ --- arch/powerpc/kernel/dt_cpu_ftrs.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/arch/powerpc/kernel/dt_cpu_ftrs.c b/arch/powerpc/kernel/dt_cpu_ftrs.c index 3af6c06af02f..4f0799c8daa9 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,8 +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 && *(char *)prop != 0) { + strscpy(dt_cpu_name, (char *)prop); cur_cpu_spec->cpu_name = dt_cpu_name; }