[patch 2/2] x86/mce/AMD: Make the init code more robust

From: Thomas Gleixner
Date: Mon Dec 26 2016 - 17:05:11 EST


If mce_device_init() fails then the mce device pointer is NULL and the AMD
mce code happily dereferences it.

Add a sanity check.

Reported-by: Markus Trippelsdorf <markus@xxxxxxxxxxxxxxx>
Reported-by: Boris Ostrovsky <boris.ostrovsky@xxxxxxxxxx>
Signed-off-by: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
---
arch/x86/kernel/cpu/mcheck/mce_amd.c | 3 +++
1 file changed, 3 insertions(+)

--- a/arch/x86/kernel/cpu/mcheck/mce_amd.c
+++ b/arch/x86/kernel/cpu/mcheck/mce_amd.c
@@ -1182,6 +1182,9 @@ static int threshold_create_bank(unsigne
const char *name = get_name(bank, NULL);
int err = 0;

+ if (!dev)
+ return -ENODEV;
+
if (is_shared_bank(bank)) {
nb = node_to_amd_nb(amd_get_nb_id(cpu));