Skip to content

Commit 6b07202

Browse files
KAGA-KOKObp3tk0v
authored andcommitted
x86/microcode/intel: Simplify and rename generic_load_microcode()
so it becomes less obfuscated and rename it because there is nothing generic about it. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Link: https://lore.kernel.org/r/20231002115902.330295409@linutronix.de
1 parent b0f0bf5 commit 6b07202

1 file changed

Lines changed: 17 additions & 30 deletions

File tree

  • arch/x86/kernel/cpu/microcode

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

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -240,19 +240,6 @@ int intel_microcode_sanity_check(void *mc, bool print_err, int hdr_type)
240240
}
241241
EXPORT_SYMBOL_GPL(intel_microcode_sanity_check);
242242

243-
/*
244-
* Returns 1 if update has been found, 0 otherwise.
245-
*/
246-
static int has_newer_microcode(void *mc, unsigned int csig, int cpf, int new_rev)
247-
{
248-
struct microcode_header_intel *mc_hdr = mc;
249-
250-
if (mc_hdr->rev <= new_rev)
251-
return 0;
252-
253-
return intel_find_matching_signature(mc, csig, cpf);
254-
}
255-
256243
static void save_microcode_patch(void *data, unsigned int size)
257244
{
258245
struct microcode_header_intel *p;
@@ -559,14 +546,12 @@ static enum ucode_state apply_microcode_intel(int cpu)
559546
return ret;
560547
}
561548

562-
static enum ucode_state generic_load_microcode(int cpu, struct iov_iter *iter)
549+
static enum ucode_state parse_microcode_blobs(int cpu, struct iov_iter *iter)
563550
{
564551
struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
565552
unsigned int curr_mc_size = 0, new_mc_size = 0;
566-
enum ucode_state ret = UCODE_OK;
567-
int new_rev = uci->cpu_sig.rev;
553+
int cur_rev = uci->cpu_sig.rev;
568554
u8 *new_mc = NULL, *mc = NULL;
569-
unsigned int csig, cpf;
570555

571556
while (iov_iter_count(iter)) {
572557
struct microcode_header_intel mc_header;
@@ -583,6 +568,7 @@ static enum ucode_state generic_load_microcode(int cpu, struct iov_iter *iter)
583568
pr_err("error! Bad data in microcode data file (totalsize too small)\n");
584569
break;
585570
}
571+
586572
data_size = mc_size - sizeof(mc_header);
587573
if (data_size > iov_iter_count(iter)) {
588574
pr_err("error! Bad data in microcode data file (truncated file?)\n");
@@ -605,16 +591,17 @@ static enum ucode_state generic_load_microcode(int cpu, struct iov_iter *iter)
605591
break;
606592
}
607593

608-
csig = uci->cpu_sig.sig;
609-
cpf = uci->cpu_sig.pf;
610-
if (has_newer_microcode(mc, csig, cpf, new_rev)) {
611-
vfree(new_mc);
612-
new_rev = mc_header.rev;
613-
new_mc = mc;
614-
new_mc_size = mc_size;
615-
mc = NULL; /* trigger new vmalloc */
616-
ret = UCODE_NEW;
617-
}
594+
if (cur_rev >= mc_header.rev)
595+
continue;
596+
597+
if (!intel_find_matching_signature(mc, uci->cpu_sig.sig, uci->cpu_sig.pf))
598+
continue;
599+
600+
vfree(new_mc);
601+
cur_rev = mc_header.rev;
602+
new_mc = mc;
603+
new_mc_size = mc_size;
604+
mc = NULL;
618605
}
619606

620607
vfree(mc);
@@ -634,9 +621,9 @@ static enum ucode_state generic_load_microcode(int cpu, struct iov_iter *iter)
634621
save_microcode_patch(new_mc, new_mc_size);
635622

636623
pr_debug("CPU%d found a matching microcode update with version 0x%x (current=0x%x)\n",
637-
cpu, new_rev, uci->cpu_sig.rev);
624+
cpu, cur_rev, uci->cpu_sig.rev);
638625

639-
return ret;
626+
return UCODE_NEW;
640627
}
641628

642629
static bool is_blacklisted(unsigned int cpu)
@@ -685,7 +672,7 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
685672
kvec.iov_base = (void *)firmware->data;
686673
kvec.iov_len = firmware->size;
687674
iov_iter_kvec(&iter, ITER_SOURCE, &kvec, 1, firmware->size);
688-
ret = generic_load_microcode(cpu, &iter);
675+
ret = parse_microcode_blobs(cpu, &iter);
689676

690677
release_firmware(firmware);
691678

0 commit comments

Comments
 (0)