[patch V3 04/30] x86/microcode/intel: Simplify scan_microcode()

Thomas Gleixner posted 30 patches 2 years, 3 months ago
There is a newer version of this series
[patch V3 04/30] x86/microcode/intel: Simplify scan_microcode()
Posted by Thomas Gleixner 2 years, 3 months ago
Make it readable and comprehensible.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 arch/x86/kernel/cpu/microcode/intel.c |   30 ++++++++----------------------
 1 file changed, 8 insertions(+), 22 deletions(-)

--- a/arch/x86/kernel/cpu/microcode/intel.c
+++ b/arch/x86/kernel/cpu/microcode/intel.c
@@ -265,25 +265,19 @@ static void save_microcode_patch(void *d
 		return;
 
 	/* Save for early loading */
-	intel_ucode_patch = (struct microcode_intel *)p;
+		intel_ucode_patch = (struct microcode_intel *)p;
 }
 
-/*
- * Get microcode matching with BSP's model. Only CPUs with the same model as
- * BSP can stay in the platform.
- */
-static struct microcode_intel *
-scan_microcode(void *data, size_t size, struct ucode_cpu_info *uci, bool save)
+/* Scan CPIO for microcode matching the boot CPUs family, model, stepping */
+static struct microcode_intel *scan_microcode(void *data, size_t size,
+					      struct ucode_cpu_info *uci, bool save)
 {
 	struct microcode_header_intel *mc_header;
 	struct microcode_intel *patch = NULL;
 	u32 cur_rev = uci->cpu_sig.rev;
 	unsigned int mc_size;
 
-	while (size) {
-		if (size < sizeof(struct microcode_header_intel))
-			break;
-
+	for (; size >= sizeof(struct microcode_header_intel); size -= mc_size, data += mc_size) {
 		mc_header = (struct microcode_header_intel *)data;
 
 		mc_size = get_totalsize(mc_header);
@@ -291,27 +285,19 @@ scan_microcode(void *data, size_t size,
 		    intel_microcode_sanity_check(data, false, MC_HEADER_TYPE_MICROCODE) < 0)
 			break;
 
-		size -= mc_size;
-
-		if (!intel_find_matching_signature(data, uci->cpu_sig.sig,
-						   uci->cpu_sig.pf)) {
-			data += mc_size;
+		if (!intel_find_matching_signature(data, uci->cpu_sig.sig, uci->cpu_sig.pf))
 			continue;
-		}
 
 		/* BSP scan: Check whether there is newer microcode */
 		if (!save && cur_rev >= mc_header->rev)
-			goto next;
+			continue;
 
 		/* Save scan: Check whether there is newer or matching microcode */
 		if (save && cur_rev != mc_header->rev)
-			goto next;
+			continue;
 
 		patch = data;
 		cur_rev = mc_header->rev;
-
-next:
-		data += mc_size;
 	}
 
 	if (size)
Re: [patch V3 04/30] x86/microcode/intel: Simplify scan_microcode()
Posted by Borislav Petkov 2 years, 3 months ago
On Tue, Sep 12, 2023 at 09:57:49AM +0200, Thomas Gleixner wrote:
> Make it readable and comprehensible.
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> ---
>  arch/x86/kernel/cpu/microcode/intel.c |   30 ++++++++----------------------
>  1 file changed, 8 insertions(+), 22 deletions(-)
> 
> --- a/arch/x86/kernel/cpu/microcode/intel.c
> +++ b/arch/x86/kernel/cpu/microcode/intel.c
> @@ -265,25 +265,19 @@ static void save_microcode_patch(void *d
>  		return;
>  
>  	/* Save for early loading */
> -	intel_ucode_patch = (struct microcode_intel *)p;
> +		intel_ucode_patch = (struct microcode_intel *)p;

This got committed by mistake.

> -/*
> - * Get microcode matching with BSP's model. Only CPUs with the same model as
> - * BSP can stay in the platform.
> - */
> -static struct microcode_intel *
> -scan_microcode(void *data, size_t size, struct ucode_cpu_info *uci, bool save)
> +/* Scan CPIO for microcode matching the boot CPUs family, model, stepping */

"... the boot CPU's... " or simply the "BSP's".

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette