[PATCH 10/10] x86, mce: move mce_log_init() into mce_cap_init()

From: Hidetoshi Seto
Date: Mon Oct 05 2009 - 02:46:36 EST


The mce_log_init() should be able to return -ENOMEM, to abort all following
initialization in mce.c. It can be done in same style with mce_banks_init()
so I moved mce_log_init() into mce_cap_init() too.

And put __cpuinit to mce_banks_init().

Signed-off-by: Hidetoshi Seto <seto.hidetoshi@xxxxxxxxxxxxxx>
---
arch/x86/kernel/cpu/mcheck/mce.c | 48 +++++++++++++++++++++++--------------
1 files changed, 30 insertions(+), 18 deletions(-)

diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
index 63a7820..fad3daa 100644
--- a/arch/x86/kernel/cpu/mcheck/mce.c
+++ b/arch/x86/kernel/cpu/mcheck/mce.c
@@ -1194,19 +1194,40 @@ int mce_notify_irq(void)
}
EXPORT_SYMBOL_GPL(mce_notify_irq);

-static int mce_banks_init(void)
+static __cpuinit int mce_banks_init(void)
{
int i;

mce_banks = kzalloc(banks * sizeof(struct mce_bank), GFP_KERNEL);
if (!mce_banks)
return -ENOMEM;
+
for (i = 0; i < banks; i++) {
struct mce_bank *b = &mce_banks[i];

b->ctl = -1ULL;
b->init = 1;
}
+
+ return 0;
+}
+
+/*
+ * Initialize MCE per-CPU log buffer
+ */
+static __cpuinit int mce_log_init(void)
+{
+ int cpu;
+
+ mcelog.nr_mcelog_cpus = num_possible_cpus();
+ mcelog.mcelog_cpus = kzalloc(sizeof(void *) * num_possible_cpus(),
+ GFP_KERNEL);
+ if (!mcelog.mcelog_cpus)
+ return -ENOMEM;
+
+ for_each_possible_cpu(cpu)
+ mcelog.mcelog_cpus[cpu] = &per_cpu(mce_log_cpus, cpu);
+
return 0;
}

@@ -1233,6 +1254,7 @@ static int __cpuinit mce_cap_init(void)
/* Don't support asymmetric configurations today */
WARN_ON(banks != 0 && b != banks);
banks = b;
+
if (!mce_banks) {
int err = mce_banks_init();

@@ -1240,6 +1262,13 @@ static int __cpuinit mce_cap_init(void)
return err;
}

+ if (!mcelog.mcelog_cpus) {
+ int err = mce_log_init();
+
+ if (err)
+ return err;
+ }
+
/* Use accurate RIP reporting if available. */
if ((cap & MCG_EXT_P) && MCG_EXT_CNT(cap) >= 9)
rip_msr = MSR_IA32_MCG_EIP;
@@ -1250,22 +1279,6 @@ static int __cpuinit mce_cap_init(void)
return 0;
}

-/*
- * Initialize MCE per-CPU log buffer
- */
-static __cpuinit void mce_log_init(void)
-{
- int cpu;
-
- if (mcelog.mcelog_cpus)
- return;
- mcelog.nr_mcelog_cpus = num_possible_cpus();
- mcelog.mcelog_cpus = kzalloc(sizeof(void *) * num_possible_cpus(),
- GFP_KERNEL);
- for_each_possible_cpu(cpu)
- mcelog.mcelog_cpus[cpu] = &per_cpu(mce_log_cpus, cpu);
-}
-
static void mce_init(void)
{
mce_banks_t all_banks;
@@ -1436,7 +1449,6 @@ void __cpuinit mcheck_init(struct cpuinfo_x86 *c)
mce_disabled = 1;
return;
}
- mce_log_init();

machine_check_vector = do_machine_check;

--
1.6.4.3


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/