[PATCH 04/10] x86: mce: fix error handling

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



mcheck_init_device() poorly handles errors. If any request fails
unregister and free everything.

Signed-off-by: Kulikov Vasiliy <segooon@xxxxxxxxx>
---
 arch/x86/kernel/cpu/mcheck/mce.c |   24 ++++++++++++++++++++----
 1 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
index ed41562..a1119f1 100644
--- a/arch/x86/kernel/cpu/mcheck/mce.c
+++ b/arch/x86/kernel/cpu/mcheck/mce.c
@@ -2124,22 +2124,38 @@ static __init int mcheck_init_device(void)
 	if (!mce_available(&boot_cpu_data))
 		return -EIO;
 
-	zalloc_cpumask_var(&mce_dev_initialized, GFP_KERNEL);
+	if (!zalloc_cpumask_var(&mce_dev_initialized, GFP_KERNEL))
+		return -ENOMEM;
 
 	mce_init_banks();
 
 	err = sysdev_class_register(&mce_sysclass);
 	if (err)
-		return err;
+		goto err_free_cpumask_var;
 
 	for_each_online_cpu(i) {
 		err = mce_create_device(i);
 		if (err)
-			return err;
+			goto mce_remove_devices;
 	}
 
 	register_hotcpu_notifier(&mce_cpu_notifier);
-	misc_register(&mce_log_device);
+	err = misc_register(&mce_log_device);
+	if (err)
+		goto err_unreg_notifier;
+	return 0;
+
+err_unreg_notifier:
+	unregister_hotcpu_notifier(&mce_cpu_notifier);
+
+mce_remove_devices:
+	for_each_online_cpu(i)
+		mce_remove_device(i);
+
+	sysdev_class_unregister(&mce_sysclass);
+
+err_free_cpumask_var:
+	free_cpumask_var(mce_dev_initialized);
 
 	return err;
 }
-- 
1.7.0.4

--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Kernel Development]     [Kernel Announce]     [Kernel Newbies]     [Linux Networking Development]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Device Mapper]

  Powered by Linux