Commit 4fe9349f authored by Borislav Petkov's avatar Borislav Petkov Committed by Ingo Molnar

x86/microcode/intel: Rename mc_saved_count to num_saved

It is shorter and easier on the eyes. Change the "== 0" tests to "!..."
while at it.
Tested-by: default avatarThomas Voegtle <tv@lio96.de>
Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/1454499225-21544-9-git-send-email-bp@alien8.deSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent bd6fe58d
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
static unsigned long mc_saved_in_initrd[MAX_UCODE_COUNT]; static unsigned long mc_saved_in_initrd[MAX_UCODE_COUNT];
static struct mc_saved_data { static struct mc_saved_data {
unsigned int mc_saved_count; unsigned int num_saved;
struct microcode_intel **mc_saved; struct microcode_intel **mc_saved;
} mc_saved_data; } mc_saved_data;
...@@ -96,7 +96,7 @@ microcode_phys(struct microcode_intel **mc_saved_tmp, struct mc_saved_data *mcs) ...@@ -96,7 +96,7 @@ microcode_phys(struct microcode_intel **mc_saved_tmp, struct mc_saved_data *mcs)
mc_saved = (struct microcode_intel ***)__pa_nodebug(&mcs->mc_saved); mc_saved = (struct microcode_intel ***)__pa_nodebug(&mcs->mc_saved);
for (i = 0; i < mcs->mc_saved_count; i++) { for (i = 0; i < mcs->num_saved; i++) {
struct microcode_intel *p; struct microcode_intel *p;
p = *(struct microcode_intel **)__pa_nodebug(mcs->mc_saved + i); p = *(struct microcode_intel **)__pa_nodebug(mcs->mc_saved + i);
...@@ -110,7 +110,7 @@ load_microcode(struct mc_saved_data *mcs, unsigned long *initrd, ...@@ -110,7 +110,7 @@ load_microcode(struct mc_saved_data *mcs, unsigned long *initrd,
unsigned long initrd_start, struct ucode_cpu_info *uci) unsigned long initrd_start, struct ucode_cpu_info *uci)
{ {
struct microcode_intel *mc_saved_tmp[MAX_UCODE_COUNT]; struct microcode_intel *mc_saved_tmp[MAX_UCODE_COUNT];
unsigned int count = mcs->mc_saved_count; unsigned int count = mcs->num_saved;
if (!mcs->mc_saved) { if (!mcs->mc_saved) {
copy_initrd_ptrs(mc_saved_tmp, initrd, initrd_start, count); copy_initrd_ptrs(mc_saved_tmp, initrd, initrd_start, count);
...@@ -174,23 +174,23 @@ matching_model_microcode(struct microcode_header_intel *mc_header, ...@@ -174,23 +174,23 @@ matching_model_microcode(struct microcode_header_intel *mc_header,
static int static int
save_microcode(struct mc_saved_data *mcs, save_microcode(struct mc_saved_data *mcs,
struct microcode_intel **mc_saved_src, struct microcode_intel **mc_saved_src,
unsigned int mc_saved_count) unsigned int num_saved)
{ {
int i, j; int i, j;
struct microcode_intel **saved_ptr; struct microcode_intel **saved_ptr;
int ret; int ret;
if (!mc_saved_count) if (!num_saved)
return -EINVAL; return -EINVAL;
/* /*
* Copy new microcode data. * Copy new microcode data.
*/ */
saved_ptr = kcalloc(mc_saved_count, sizeof(struct microcode_intel *), GFP_KERNEL); saved_ptr = kcalloc(num_saved, sizeof(struct microcode_intel *), GFP_KERNEL);
if (!saved_ptr) if (!saved_ptr)
return -ENOMEM; return -ENOMEM;
for (i = 0; i < mc_saved_count; i++) { for (i = 0; i < num_saved; i++) {
struct microcode_header_intel *mc_hdr; struct microcode_header_intel *mc_hdr;
struct microcode_intel *mc; struct microcode_intel *mc;
unsigned long size; unsigned long size;
...@@ -216,8 +216,8 @@ save_microcode(struct mc_saved_data *mcs, ...@@ -216,8 +216,8 @@ save_microcode(struct mc_saved_data *mcs,
/* /*
* Point to newly saved microcode. * Point to newly saved microcode.
*/ */
mcs->mc_saved = saved_ptr; mcs->mc_saved = saved_ptr;
mcs->mc_saved_count = mc_saved_count; mcs->num_saved = num_saved;
return 0; return 0;
...@@ -293,10 +293,10 @@ get_matching_model_microcode(int cpu, unsigned long start, ...@@ -293,10 +293,10 @@ get_matching_model_microcode(int cpu, unsigned long start,
unsigned int mc_size; unsigned int mc_size;
struct microcode_header_intel *mc_header; struct microcode_header_intel *mc_header;
struct microcode_intel *mc_saved_tmp[MAX_UCODE_COUNT]; struct microcode_intel *mc_saved_tmp[MAX_UCODE_COUNT];
unsigned int mc_saved_count = mcs->mc_saved_count; unsigned int num_saved = mcs->num_saved;
int i; int i;
while (leftover && mc_saved_count < ARRAY_SIZE(mc_saved_tmp)) { while (leftover && num_saved < ARRAY_SIZE(mc_saved_tmp)) {
if (leftover < sizeof(mc_header)) if (leftover < sizeof(mc_header))
break; break;
...@@ -321,7 +321,7 @@ get_matching_model_microcode(int cpu, unsigned long start, ...@@ -321,7 +321,7 @@ get_matching_model_microcode(int cpu, unsigned long start,
continue; continue;
} }
mc_saved_count = _save_mc(mc_saved_tmp, ucode_ptr, mc_saved_count); num_saved = _save_mc(mc_saved_tmp, ucode_ptr, num_saved);
ucode_ptr += mc_size; ucode_ptr += mc_size;
} }
...@@ -331,15 +331,15 @@ get_matching_model_microcode(int cpu, unsigned long start, ...@@ -331,15 +331,15 @@ get_matching_model_microcode(int cpu, unsigned long start,
goto out; goto out;
} }
if (mc_saved_count == 0) { if (!num_saved) {
state = UCODE_NFOUND; state = UCODE_NFOUND;
goto out; goto out;
} }
for (i = 0; i < mc_saved_count; i++) for (i = 0; i < num_saved; i++)
mc_saved_in_initrd[i] = (unsigned long)mc_saved_tmp[i] - start; mc_saved_in_initrd[i] = (unsigned long)mc_saved_tmp[i] - start;
mcs->mc_saved_count = mc_saved_count; mcs->num_saved = num_saved;
out: out:
return state; return state;
} }
...@@ -393,11 +393,11 @@ static void show_saved_mc(void) ...@@ -393,11 +393,11 @@ static void show_saved_mc(void)
unsigned int sig, pf, rev, total_size, data_size, date; unsigned int sig, pf, rev, total_size, data_size, date;
struct ucode_cpu_info uci; struct ucode_cpu_info uci;
if (mc_saved_data.mc_saved_count == 0) { if (!mc_saved_data.num_saved) {
pr_debug("no microcode data saved.\n"); pr_debug("no microcode data saved.\n");
return; return;
} }
pr_debug("Total microcode saved: %d\n", mc_saved_data.mc_saved_count); pr_debug("Total microcode saved: %d\n", mc_saved_data.num_saved);
collect_cpu_info_early(&uci); collect_cpu_info_early(&uci);
...@@ -406,7 +406,7 @@ static void show_saved_mc(void) ...@@ -406,7 +406,7 @@ static void show_saved_mc(void)
rev = uci.cpu_sig.rev; rev = uci.cpu_sig.rev;
pr_debug("CPU: sig=0x%x, pf=0x%x, rev=0x%x\n", sig, pf, rev); pr_debug("CPU: sig=0x%x, pf=0x%x, rev=0x%x\n", sig, pf, rev);
for (i = 0; i < mc_saved_data.mc_saved_count; i++) { for (i = 0; i < mc_saved_data.num_saved; i++) {
struct microcode_header_intel *mc_saved_header; struct microcode_header_intel *mc_saved_header;
struct extended_sigtable *ext_header; struct extended_sigtable *ext_header;
int ext_sigcount; int ext_sigcount;
...@@ -462,7 +462,7 @@ int save_mc_for_early(u8 *mc) ...@@ -462,7 +462,7 @@ int save_mc_for_early(u8 *mc)
{ {
struct microcode_intel *mc_saved_tmp[MAX_UCODE_COUNT]; struct microcode_intel *mc_saved_tmp[MAX_UCODE_COUNT];
unsigned int mc_saved_count_init; unsigned int mc_saved_count_init;
unsigned int mc_saved_count; unsigned int num_saved;
struct microcode_intel **mc_saved; struct microcode_intel **mc_saved;
int ret = 0; int ret = 0;
int i; int i;
...@@ -473,23 +473,23 @@ int save_mc_for_early(u8 *mc) ...@@ -473,23 +473,23 @@ int save_mc_for_early(u8 *mc)
*/ */
mutex_lock(&x86_cpu_microcode_mutex); mutex_lock(&x86_cpu_microcode_mutex);
mc_saved_count_init = mc_saved_data.mc_saved_count; mc_saved_count_init = mc_saved_data.num_saved;
mc_saved_count = mc_saved_data.mc_saved_count; num_saved = mc_saved_data.num_saved;
mc_saved = mc_saved_data.mc_saved; mc_saved = mc_saved_data.mc_saved;
if (mc_saved && mc_saved_count) if (mc_saved && num_saved)
memcpy(mc_saved_tmp, mc_saved, memcpy(mc_saved_tmp, mc_saved,
mc_saved_count * sizeof(struct microcode_intel *)); num_saved * sizeof(struct microcode_intel *));
/* /*
* Save the microcode patch mc in mc_save_tmp structure if it's a newer * Save the microcode patch mc in mc_save_tmp structure if it's a newer
* version. * version.
*/ */
mc_saved_count = _save_mc(mc_saved_tmp, mc, mc_saved_count); num_saved = _save_mc(mc_saved_tmp, mc, num_saved);
/* /*
* Save the mc_save_tmp in global mc_saved_data. * Save the mc_save_tmp in global mc_saved_data.
*/ */
ret = save_microcode(&mc_saved_data, mc_saved_tmp, mc_saved_count); ret = save_microcode(&mc_saved_data, mc_saved_tmp, num_saved);
if (ret) { if (ret) {
pr_err("Cannot save microcode patch.\n"); pr_err("Cannot save microcode patch.\n");
goto out; goto out;
...@@ -681,14 +681,15 @@ static int apply_microcode_early(struct ucode_cpu_info *uci, bool early) ...@@ -681,14 +681,15 @@ static int apply_microcode_early(struct ucode_cpu_info *uci, bool early)
*/ */
int __init save_microcode_in_initrd_intel(void) int __init save_microcode_in_initrd_intel(void)
{ {
unsigned int count = mc_saved_data.mc_saved_count; unsigned int count = mc_saved_data.num_saved;
struct microcode_intel *mc_saved[MAX_UCODE_COUNT]; struct microcode_intel *mc_saved[MAX_UCODE_COUNT];
int ret = 0; int ret = 0;
if (count == 0) if (!count)
return ret; return ret;
copy_initrd_ptrs(mc_saved, mc_saved_in_initrd, get_initrd_start(), count); copy_initrd_ptrs(mc_saved, mc_saved_in_initrd, get_initrd_start(), count);
ret = save_microcode(&mc_saved_data, mc_saved, count); ret = save_microcode(&mc_saved_data, mc_saved, count);
if (ret) if (ret)
pr_err("Cannot save microcode patches from initrd.\n"); pr_err("Cannot save microcode patches from initrd.\n");
...@@ -763,7 +764,7 @@ void load_ucode_intel_ap(void) ...@@ -763,7 +764,7 @@ void load_ucode_intel_ap(void)
* If there is no valid ucode previously saved in memory, no need to * If there is no valid ucode previously saved in memory, no need to
* update ucode on this AP. * update ucode on this AP.
*/ */
if (mcs_p->mc_saved_count == 0) if (!mcs_p->num_saved)
return; return;
collect_cpu_info_early(&uci); collect_cpu_info_early(&uci);
...@@ -781,13 +782,13 @@ void reload_ucode_intel(void) ...@@ -781,13 +782,13 @@ void reload_ucode_intel(void)
struct ucode_cpu_info uci; struct ucode_cpu_info uci;
enum ucode_state ret; enum ucode_state ret;
if (!mc_saved_data.mc_saved_count) if (!mc_saved_data.num_saved)
return; return;
collect_cpu_info_early(&uci); collect_cpu_info_early(&uci);
ret = load_microcode_early(mc_saved_data.mc_saved, ret = load_microcode_early(mc_saved_data.mc_saved,
mc_saved_data.mc_saved_count, &uci); mc_saved_data.num_saved, &uci);
if (ret != UCODE_OK) if (ret != UCODE_OK)
return; return;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment