If we try a CPU down and fail in the middle then we roll back to the
online state. This means we would perform CPU_ONLINE / mce_device_create()
without invoking CPU_DEAD / mce_device_remove() for the cleanup of what was
allocated in CPU_ONLINE.
Be prepared for this and don't allocate the struct if we have it
already.

Cc: Tony Luck <tony.l...@intel.com>
Cc: Borislav Petkov <b...@alien8.de>
Cc: linux-e...@vger.kernel.org
Cc: x...@kernel.org
Signed-off-by: Sebastian Andrzej Siewior <bige...@linutronix.de>
Signed-off-by: Thomas Gleixner <t...@linutronix.de>
---
 arch/x86/kernel/cpu/mcheck/mce.c     | 4 ++++
 arch/x86/kernel/cpu/mcheck/mce_amd.c | 4 ++++
 2 files changed, 8 insertions(+)

diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
index a7fdf453d895..e9ffd6d9e32d 100644
--- a/arch/x86/kernel/cpu/mcheck/mce.c
+++ b/arch/x86/kernel/cpu/mcheck/mce.c
@@ -2409,6 +2409,10 @@ static int mce_device_create(unsigned int cpu)
        if (!mce_available(&boot_cpu_data))
                return -EIO;
 
+       dev = per_cpu(mce_device, cpu);
+       if (dev)
+               return 0;
+
        dev = kzalloc(sizeof *dev, GFP_KERNEL);
        if (!dev)
                return -ENOMEM;
diff --git a/arch/x86/kernel/cpu/mcheck/mce_amd.c 
b/arch/x86/kernel/cpu/mcheck/mce_amd.c
index 55cd018bc1ae..e93580c82ef0 100644
--- a/arch/x86/kernel/cpu/mcheck/mce_amd.c
+++ b/arch/x86/kernel/cpu/mcheck/mce_amd.c
@@ -1097,6 +1097,10 @@ static int threshold_create_device(unsigned int cpu)
        struct threshold_bank **bp;
        int err = 0;
 
+       bp = per_cpu(threshold_banks, cpu);
+       if (bp)
+               return 0;
+
        bp = kzalloc(sizeof(struct threshold_bank *) * mca_cfg.banks,
                     GFP_KERNEL);
        if (!bp)
-- 
2.10.2

Reply via email to