Skip to content

Commit b0f0bf5

Browse files
KAGA-KOKObp3tk0v
authored andcommitted
x86/microcode/intel: Simplify scan_microcode()
Make it readable and comprehensible. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Link: https://lore.kernel.org/r/20231002115902.271940980@linutronix.de
1 parent ae76d95 commit b0f0bf5

1 file changed

Lines changed: 7 additions & 21 deletions

File tree

  • arch/x86/kernel/cpu/microcode

arch/x86/kernel/cpu/microcode/intel.c

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -266,50 +266,36 @@ static void save_microcode_patch(void *data, unsigned int size)
266266
intel_ucode_patch = (struct microcode_intel *)p;
267267
}
268268

269-
/*
270-
* Get microcode matching with BSP's model. Only CPUs with the same model as
271-
* BSP can stay in the platform.
272-
*/
273-
static struct microcode_intel *
274-
scan_microcode(void *data, size_t size, struct ucode_cpu_info *uci, bool save)
269+
/* Scan CPIO for microcode matching the boot CPU's family, model, stepping */
270+
static struct microcode_intel *scan_microcode(void *data, size_t size,
271+
struct ucode_cpu_info *uci, bool save)
275272
{
276273
struct microcode_header_intel *mc_header;
277274
struct microcode_intel *patch = NULL;
278275
u32 cur_rev = uci->cpu_sig.rev;
279276
unsigned int mc_size;
280277

281-
while (size) {
282-
if (size < sizeof(struct microcode_header_intel))
283-
break;
284-
278+
for (; size >= sizeof(struct microcode_header_intel); size -= mc_size, data += mc_size) {
285279
mc_header = (struct microcode_header_intel *)data;
286280

287281
mc_size = get_totalsize(mc_header);
288282
if (!mc_size || mc_size > size ||
289283
intel_microcode_sanity_check(data, false, MC_HEADER_TYPE_MICROCODE) < 0)
290284
break;
291285

292-
size -= mc_size;
293-
294-
if (!intel_find_matching_signature(data, uci->cpu_sig.sig,
295-
uci->cpu_sig.pf)) {
296-
data += mc_size;
286+
if (!intel_find_matching_signature(data, uci->cpu_sig.sig, uci->cpu_sig.pf))
297287
continue;
298-
}
299288

300289
/* BSP scan: Check whether there is newer microcode */
301290
if (!save && cur_rev >= mc_header->rev)
302-
goto next;
291+
continue;
303292

304293
/* Save scan: Check whether there is newer or matching microcode */
305294
if (save && cur_rev != mc_header->rev)
306-
goto next;
295+
continue;
307296

308297
patch = data;
309298
cur_rev = mc_header->rev;
310-
311-
next:
312-
data += mc_size;
313299
}
314300

315301
if (size)

0 commit comments

Comments
 (0)