All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86: mce: Potential memory leaks when initializing mcheck devices
@ 2011-03-03 19:12 Johan Wessfeldt
  2011-03-04 10:51 ` [PATCH] x86: mce: Potential memory leaks when initializing Dan Carpenter
  0 siblings, 1 reply; 2+ messages in thread
From: Johan Wessfeldt @ 2011-03-03 19:12 UTC (permalink / raw)
  To: kernel-janitors

This patch makes sure cleanup is done properly when mcheck fails
initializing any of its resources.

Note!
It should be safe to call mce_remove_device on ANY of the cpus as
mce_remove_device checks if corresponding cpu was initialized
before removing its resources.

Please review.

Signed-off-by: Johan Wessfeldt <johan.wessfeldt@gmail.com>
---
 arch/x86/kernel/cpu/mcheck/mce.c |   26 ++++++++++++++++++++------
 1 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
index d916183..a9e3820 100644
--- a/arch/x86/kernel/cpu/mcheck/mce.c
+++ b/arch/x86/kernel/cpu/mcheck/mce.c
@@ -2122,8 +2122,10 @@ static __init int mcheck_init_device(void)
 	int err;
 	int i = 0;
 
-	if (!mce_available(&boot_cpu_data))
-		return -EIO;
+	if (!mce_available(&boot_cpu_data)) {
+		err = -EIO;
+		goto out;
+	}
 
 	zalloc_cpumask_var(&mce_dev_initialized, GFP_KERNEL);
 
@@ -2131,20 +2133,32 @@ static __init int mcheck_init_device(void)
 
 	err = sysdev_class_register(&mce_sysclass);
 	if (err)
-		return err;
+		goto out;
 
 	for_each_online_cpu(i) {
 		err = mce_create_device(i);
 		if (err)
-			return err;
+			goto out_unreg;
 	}
 
 	register_hotcpu_notifier(&mce_cpu_notifier);
-	misc_register(&mce_log_device);
+	err = misc_register(&mce_log_device);
+	if (err)
+		goto out_unreg_hotcpu;
+
+	return 0;
 
+out_unreg_hotcpu:
+	unregister_hotcpu_notifier(&mce_cpu_notifier);
+out_unreg:
+	i = 0;
+	for_each_online_cpu(i)
+		mce_remove_device(i);
+
+	sysdev_class_unregister(&mce_sysclass);
+out:
 	return err;
 }
-
 device_initcall(mcheck_init_device);
 
 /*
-- 
1.7.2.3


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-03-04 10:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-03 19:12 [PATCH] x86: mce: Potential memory leaks when initializing mcheck devices Johan Wessfeldt
2011-03-04 10:51 ` [PATCH] x86: mce: Potential memory leaks when initializing Dan Carpenter

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.