Skip to content

Commit 9c15a24

Browse files
souchsuryasaimadhu
authored andcommitted
x86/mce: Improve mcheck_init_device() error handling
Check return code of every function called by mcheck_init_device(). Signed-off-by: Mathieu Souchaud <mattieu.souchaud@free.fr> Link: http://lkml.kernel.org/r/1399151031-19905-1-git-send-email-mattieu.souchaud@free.fr Signed-off-by: Borislav Petkov <bp@suse.de>
1 parent c720816 commit 9c15a24

File tree

1 file changed

+40
-7
lines changed
  • arch/x86/kernel/cpu/mcheck

1 file changed

+40
-7
lines changed

arch/x86/kernel/cpu/mcheck/mce.c

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2437,32 +2437,65 @@ static __init int mcheck_init_device(void)
24372437
int err;
24382438
int i = 0;
24392439

2440-
if (!mce_available(&boot_cpu_data))
2441-
return -EIO;
2440+
if (!mce_available(&boot_cpu_data)) {
2441+
err = -EIO;
2442+
goto err_out;
2443+
}
24422444

2443-
zalloc_cpumask_var(&mce_device_initialized, GFP_KERNEL);
2445+
if (!zalloc_cpumask_var(&mce_device_initialized, GFP_KERNEL)) {
2446+
err = -ENOMEM;
2447+
goto err_out;
2448+
}
24442449

24452450
mce_init_banks();
24462451

24472452
err = subsys_system_register(&mce_subsys, NULL);
24482453
if (err)
2449-
return err;
2454+
goto err_out_mem;
24502455

24512456
cpu_notifier_register_begin();
24522457
for_each_online_cpu(i) {
24532458
err = mce_device_create(i);
24542459
if (err) {
24552460
cpu_notifier_register_done();
2456-
return err;
2461+
goto err_device_create;
24572462
}
24582463
}
24592464

2460-
register_syscore_ops(&mce_syscore_ops);
24612465
__register_hotcpu_notifier(&mce_cpu_notifier);
24622466
cpu_notifier_register_done();
24632467

2468+
register_syscore_ops(&mce_syscore_ops);
2469+
24642470
/* register character device /dev/mcelog */
2465-
misc_register(&mce_chrdev_device);
2471+
err = misc_register(&mce_chrdev_device);
2472+
if (err)
2473+
goto err_register;
2474+
2475+
return 0;
2476+
2477+
err_register:
2478+
unregister_syscore_ops(&mce_syscore_ops);
2479+
2480+
cpu_notifier_register_begin();
2481+
__unregister_hotcpu_notifier(&mce_cpu_notifier);
2482+
cpu_notifier_register_done();
2483+
2484+
err_device_create:
2485+
/*
2486+
* We didn't keep track of which devices were created above, but
2487+
* even if we had, the set of online cpus might have changed.
2488+
* Play safe and remove for every possible cpu, since
2489+
* mce_device_remove() will do the right thing.
2490+
*/
2491+
for_each_possible_cpu(i)
2492+
mce_device_remove(i);
2493+
2494+
err_out_mem:
2495+
free_cpumask_var(mce_device_initialized);
2496+
2497+
err_out:
2498+
pr_err("Unable to init device /dev/mcelog (rc: %d)\n", err);
24662499

24672500
return err;
24682501
}

0 commit comments

Comments
 (0)