Skip to content

Commit

Permalink
x86/microcode/intel: Simplify update_match_cpu()
Browse files Browse the repository at this point in the history
Drop unreadable macro, deconstruct compound conditional
statement into single ones and return early if they match. Add
comments.

There should be no functionality change resulting from this
patch.

Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Quentin Casasnovas <quentin.casasnovas@oracle.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/1431860101-14847-3-git-send-email-bp@alien8.de
Signed-off-by: Ingo Molnar <mingo@kernel.org>
  • Loading branch information
Borislav Petkov authored and Ingo Molnar committed May 18, 2015
1 parent 8de3eaf commit 6b2d469
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
3 changes: 0 additions & 3 deletions arch/x86/include/asm/microcode_intel.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ struct extended_sigtable {
(((struct microcode_intel *)mc)->hdr.datasize ? \
((struct microcode_intel *)mc)->hdr.datasize : DEFAULT_UCODE_DATASIZE)

#define sigmatch(s1, s2, p1, p2) \
(((s1) == (s2)) && (((p1) & (p2)) || (((p1) == 0) && ((p2) == 0))))

#define exttable_size(et) ((et)->count * EXT_SIGNATURE_SIZE + EXT_HEADER_SIZE)

extern int has_newer_microcode(void *mc, unsigned int csig, int cpf, int rev);
Expand Down
19 changes: 13 additions & 6 deletions arch/x86/kernel/cpu/microcode/intel_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,18 @@
#include <asm/processor.h>
#include <asm/msr.h>

static inline int
update_match_cpu(unsigned int csig, unsigned int cpf,
unsigned int sig, unsigned int pf)
static inline bool cpu_signatures_match(unsigned int s1, unsigned int p1,
unsigned int s2, unsigned int p2)
{
return (!sigmatch(sig, csig, pf, cpf)) ? 0 : 1;
if (s1 != s2)
return false;

/* Processor flags are either both 0 ... */
if (!p1 && !p2)
return true;

/* ... or they intersect. */
return p1 & p2;
}

int microcode_sanity_check(void *mc, int print_err)
Expand Down Expand Up @@ -132,7 +139,7 @@ int get_matching_sig(unsigned int csig, int cpf, void *mc)
int ext_sigcount, i;
struct extended_signature *ext_sig;

if (update_match_cpu(csig, cpf, mc_header->sig, mc_header->pf))
if (cpu_signatures_match(csig, cpf, mc_header->sig, mc_header->pf))
return 1;

/* Look for ext. headers: */
Expand All @@ -144,7 +151,7 @@ int get_matching_sig(unsigned int csig, int cpf, void *mc)
ext_sig = (void *)ext_header + EXT_HEADER_SIZE;

for (i = 0; i < ext_sigcount; i++) {
if (update_match_cpu(csig, cpf, ext_sig->sig, ext_sig->pf))
if (cpu_signatures_match(csig, cpf, ext_sig->sig, ext_sig->pf))
return 1;
ext_sig++;
}
Expand Down

0 comments on commit 6b2d469

Please sign in to comment.