From nobody Fri Dec 19 00:22:00 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 9A0952528FC; Tue, 25 Mar 2025 09:05:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742893548; cv=none; b=sPrefNRxR8KL9rkF8OJBupjsBUL73AZ2tFl09fK3JyQ6SWG3sOVQ/U3JP7R8COPOvrAZukfvkNlkN78LtsOsTKVW9OwE9ZtqtFybnlyuevPIi0wZKuaFTBNlI3meH+Zug+46x3jgVj5aKH657z2NYlJbqUvSXwVLkSxEwB02/So= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742893548; c=relaxed/simple; bh=WukMsmsZn1ycMI+kiX7tKyL3oNBC1ssLSKqTg0WpTX4=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=WF9K9hRydrY3IoWrTm9XVO+6vdC1yYkIUEFqKEMPp9TlnKwb11yMTNqmXSS5aehj68yJwaXDauRP7nlq1kfRJkQyLQ+FLeQx8Uusrw4QQjl/BAy/JaLIaPDvVOOLvxbCX97/yQVvfPa3f6zBqmIlDqRx9dO13I2R11y8cBqWmq8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=LgMRehVL; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=dV7Me07y; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="LgMRehVL"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="dV7Me07y" Date: Tue, 25 Mar 2025 09:05:42 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1742893543; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=I+r/CTOZZ6RgClZkbS75+zSmcG2uC6CtVm787f/rIDo=; b=LgMRehVLlGojFi1JMTHO9MFc4YNG6bDVSccCYF/dhDZdP0trmgL1AL0GF/wxrohxsjDeA+ aRBIEssly9hUBR3Dg5Dg4erdOzcVlMmwpCRGjYqvGQpFfnC9/BkJbvSCZNkKHxZ1geNIdr I9Mx2CjqgBlWajPzgWU2pYMHAQYoA3VVRY2d4wUGNS6qYr0uqoUuSO2CMimFsRiIiECWd2 1/1fdPRxerlkDvKLYXlOKxzTt5J98Eu9mbJfzZh6eNTTq5oek3Zb1HLLSIRCOLpa60n+u5 avvBszkxmrFCoAkX5a67CWsQ2SRY97qRzmyPpsrUd43evZlrLRuWQ/ksr0+oQw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1742893543; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=I+r/CTOZZ6RgClZkbS75+zSmcG2uC6CtVm787f/rIDo=; b=dV7Me07ylKu+rhOMMd7k1fbtI63TgRUSPt1wgE9hhUNiYV2oCVztY/INJHdPDaVLDHHD4a fHUvBYpEG9KEYhBA== From: "tip-bot2 for Ahmed S. Darwish" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/cpu] tools/x86/kcpuid: Use C99-style for loops Cc: "Ahmed S. Darwish" , Ingo Molnar , "H. Peter Anvin" , Linus Torvalds , Josh Poimboeuf , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20250324142042.29010-10-darwi@linutronix.de> References: <20250324142042.29010-10-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <174289354238.14745.1979312224227532751.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the x86/cpu branch of tip: Commit-ID: 0a8f12ccd2e6edac89292af63c3a2050b4aac61b Gitweb: https://git.kernel.org/tip/0a8f12ccd2e6edac89292af63c3a2050b= 4aac61b Author: Ahmed S. Darwish AuthorDate: Mon, 24 Mar 2025 15:20:30 +01:00 Committer: Ingo Molnar CommitterDate: Tue, 25 Mar 2025 09:53:45 +01:00 tools/x86/kcpuid: Use C99-style for loops Since commit e8c07082a810 ("Kbuild: move to -std=3Dgnu11") and the kernel allows C99-style variable declarations inside of a for() loop. Adjust the kcpuid code accordingly. Note, this helps readability as some of the kcpuid functions have a huge list of variable declarations on top. Note, remove the empty lines before cpuid() invocations as it is clearer to have their parameter initialization and the actual call in one block. Signed-off-by: Ahmed S. Darwish Signed-off-by: Ingo Molnar Cc: H. Peter Anvin Cc: Linus Torvalds Cc: Josh Poimboeuf Link: https://lore.kernel.org/r/20250324142042.29010-10-darwi@linutronix.de --- tools/arch/x86/kcpuid/kcpuid.c | 52 +++++++++++++-------------------- 1 file changed, 21 insertions(+), 31 deletions(-) diff --git a/tools/arch/x86/kcpuid/kcpuid.c b/tools/arch/x86/kcpuid/kcpuid.c index 4fa768b..413e5da 100644 --- a/tools/arch/x86/kcpuid/kcpuid.c +++ b/tools/arch/x86/kcpuid/kcpuid.c @@ -172,13 +172,10 @@ static bool cpuid_store(struct cpuid_range *range, u3= 2 f, int subleaf, =20 static void raw_dump_range(struct cpuid_range *range) { - u32 f; - int i; - printf("%s Leafs :\n", range->is_ext ? "Extended" : "Basic"); printf("=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D\n"); =20 - for (f =3D 0; (int)f < range->nr; f++) { + for (u32 f =3D 0; (int)f < range->nr; f++) { struct cpuid_func *func =3D &range->funcs[f]; =20 /* Skip leaf without valid items */ @@ -186,7 +183,7 @@ static void raw_dump_range(struct cpuid_range *range) continue; =20 /* First item is the main leaf, followed by all subleafs */ - for (i =3D 0; i < func->nr; i++) + for (int i =3D 0; i < func->nr; i++) leaf_print_raw(&func->leafs[i]); } } @@ -194,15 +191,14 @@ static void raw_dump_range(struct cpuid_range *range) #define MAX_SUBLEAF_NUM 64 struct cpuid_range *setup_cpuid_range(u32 input_eax) { - u32 max_func, idx_func, subleaf, max_subleaf; - u32 eax, ebx, ecx, edx, f =3D input_eax; struct cpuid_range *range; - bool allzero; + u32 max_func, idx_func; + u32 eax, ebx, ecx, edx; =20 eax =3D input_eax; ebx =3D ecx =3D edx =3D 0; - cpuid(&eax, &ebx, &ecx, &edx); + max_func =3D eax; idx_func =3D (max_func & 0xffff) + 1; =20 @@ -222,20 +218,21 @@ struct cpuid_range *setup_cpuid_range(u32 input_eax) range->nr =3D idx_func; memset(range->funcs, 0, sizeof(struct cpuid_func) * idx_func); =20 - for (; f <=3D max_func; f++) { - eax =3D f; - subleaf =3D ecx =3D 0; + for (u32 f =3D input_eax; f <=3D max_func; f++) { + u32 max_subleaf =3D MAX_SUBLEAF_NUM; + bool allzero; =20 + eax =3D f; + ecx =3D 0; cpuid(&eax, &ebx, &ecx, &edx); - allzero =3D cpuid_store(range, f, subleaf, eax, ebx, ecx, edx); + + allzero =3D cpuid_store(range, f, 0, eax, ebx, ecx, edx); if (allzero) continue; =20 if (!has_subleafs(f)) continue; =20 - max_subleaf =3D MAX_SUBLEAF_NUM; - /* * Some can provide the exact number of subleafs, * others have to be tried (0xf) @@ -253,13 +250,12 @@ struct cpuid_range *setup_cpuid_range(u32 input_eax) if (f =3D=3D 0x80000026) max_subleaf =3D 5; =20 - for (subleaf =3D 1; subleaf < max_subleaf; subleaf++) { + for (u32 subleaf =3D 1; subleaf < max_subleaf; subleaf++) { eax =3D f; ecx =3D subleaf; - cpuid(&eax, &ebx, &ecx, &edx); - allzero =3D cpuid_store(range, f, subleaf, - eax, ebx, ecx, edx); + + allzero =3D cpuid_store(range, f, subleaf, eax, ebx, ecx, edx); if (allzero) continue; } @@ -280,12 +276,10 @@ struct cpuid_range *setup_cpuid_range(u32 input_eax) static void parse_line(char *line) { char *str; - int i; struct cpuid_range *range; struct cpuid_func *func; struct subleaf *leaf; u32 index; - u32 sub; char buffer[512]; char *buf; /* @@ -312,7 +306,7 @@ static void parse_line(char *line) strncpy(buffer, line, 511); buffer[511] =3D 0; str =3D buffer; - for (i =3D 0; i < 5; i++) { + for (int i =3D 0; i < 5; i++) { tokens[i] =3D strtok(str, ","); if (!tokens[i]) goto err_exit; @@ -378,7 +372,7 @@ static void parse_line(char *line) bit_end =3D strtoul(end, NULL, 0); bit_start =3D (start) ? strtoul(start, NULL, 0) : bit_end; =20 - for (sub =3D subleaf_start; sub <=3D subleaf_end; sub++) { + for (u32 sub =3D subleaf_start; sub <=3D subleaf_end; sub++) { leaf =3D &func->leafs[sub]; reg =3D &leaf->info[reg_index]; bdesc =3D ®->descs[reg->nr++]; @@ -432,10 +426,10 @@ static void parse_text(void) static void show_reg(const struct reg_desc *rdesc, u32 value) { const struct bits_desc *bdesc; - int start, end, i; + int start, end; u32 mask; =20 - for (i =3D 0; i < rdesc->nr; i++) { + for (int i =3D 0; i < rdesc->nr; i++) { bdesc =3D &rdesc->descs[i]; =20 start =3D bdesc->start; @@ -487,17 +481,13 @@ static void show_leaf(struct subleaf *leaf) =20 static void show_func(struct cpuid_func *func) { - int i; - - for (i =3D 0; i < func->nr; i++) + for (int i =3D 0; i < func->nr; i++) show_leaf(&func->leafs[i]); } =20 static void show_range(struct cpuid_range *range) { - int i; - - for (i =3D 0; i < range->nr; i++) + for (int i =3D 0; i < range->nr; i++) show_func(&range->funcs[i]); }