x86/mce/AMD: Make the init code more robust
authorThomas Gleixner <[email protected]>
Mon, 26 Dec 2016 21:58:20 +0000 (22:58 +0100)
committerLinus Torvalds <[email protected]>
Tue, 27 Dec 2016 01:30:24 +0000 (17:30 -0800)
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 <[email protected]>
Reported-by: Boris Ostrovsky <[email protected]>
Signed-off-by: Thomas Gleixner <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
arch/x86/kernel/cpu/mcheck/mce_amd.c

index ffacfdcacb85eafd145228d0e0d3e4765b2177ea..a5fd137417a27278f49f3cf0b60803997176a665 100644 (file)
@@ -1182,6 +1182,9 @@ static int threshold_create_bank(unsigned int cpu, unsigned int bank)
        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));