* [PATCH] x86: mce: Potential memory leaks when initializing mcheck devices
@ 2011-03-04 18:31 Johan Wessfeldt
2011-03-07 6:56 ` Johan Wessfeldt
0 siblings, 1 reply; 3+ messages in thread
From: Johan Wessfeldt @ 2011-03-04 18:31 UTC (permalink / raw)
To: tglx; +Cc: x86, linux-kernel, Johan Wessfeldt
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 | 17 ++++++++++++++---
1 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
index d916183..273f2f6 100644
--- a/arch/x86/kernel/cpu/mcheck/mce.c
+++ b/arch/x86/kernel/cpu/mcheck/mce.c
@@ -2136,15 +2136,26 @@ static __init int mcheck_init_device(void)
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:
+ for_each_online_cpu(i)
+ mce_remove_device(i);
+ sysdev_class_unregister(&mce_sysclass);
+ free_cpumask_var(mce_dev_initialized);
return err;
}
-
device_initcall(mcheck_init_device);
/*
--
1.7.2.3
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] x86: mce: Potential memory leaks when initializing mcheck devices
2011-03-04 18:31 [PATCH] x86: mce: Potential memory leaks when initializing mcheck devices Johan Wessfeldt
@ 2011-03-07 6:56 ` Johan Wessfeldt
2011-03-07 10:36 ` [PATCH V2] " Johan Wessfeldt
0 siblings, 1 reply; 3+ messages in thread
From: Johan Wessfeldt @ 2011-03-07 6:56 UTC (permalink / raw)
To: tglx; +Cc: x86, linux-kernel, Johan Wessfeldt
Oops
missed another call to free_cpumask_var(). Will send a v2 patch
Regards
// Johan W
On Fri, Mar 4, 2011 at 7:31 PM, Johan Wessfeldt
<johan.wessfeldt@gmail.com> wrote:
> 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 | 17 ++++++++++++++---
> 1 files changed, 14 insertions(+), 3 deletions(-)
>
> diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
> index d916183..273f2f6 100644
> --- a/arch/x86/kernel/cpu/mcheck/mce.c
> +++ b/arch/x86/kernel/cpu/mcheck/mce.c
> @@ -2136,15 +2136,26 @@ static __init int mcheck_init_device(void)
> 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:
> + for_each_online_cpu(i)
> + mce_remove_device(i);
>
> + sysdev_class_unregister(&mce_sysclass);
> + free_cpumask_var(mce_dev_initialized);
> return err;
> }
> -
> device_initcall(mcheck_init_device);
>
> /*
> --
> 1.7.2.3
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread* [PATCH V2] x86: mce: Potential memory leaks when initializing mcheck devices
2011-03-07 6:56 ` Johan Wessfeldt
@ 2011-03-07 10:36 ` Johan Wessfeldt
0 siblings, 0 replies; 3+ messages in thread
From: Johan Wessfeldt @ 2011-03-07 10:36 UTC (permalink / raw)
Cc: x86, tglx, linux-kernel, Johan Wessfeldt
This patch makes sure cleanup is done properly when mcheck fails
initializing any of its resources.
Signed-off-by: Johan Wessfeldt <johan.wessfeldt@gmail.com>
---
v2: call free_cpumask_var() if sysdev_class_register() fails
arch/x86/kernel/cpu/mcheck/mce.c | 20 ++++++++++++++++----
1 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
index d916183..3cbd5a0 100644
--- a/arch/x86/kernel/cpu/mcheck/mce.c
+++ b/arch/x86/kernel/cpu/mcheck/mce.c
@@ -2131,20 +2131,32 @@ static __init int mcheck_init_device(void)
err = sysdev_class_register(&mce_sysclass);
if (err)
- return err;
+ goto out_free;
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:
+ for_each_online_cpu(i)
+ mce_remove_device(i);
+
+ sysdev_class_unregister(&mce_sysclass);
+out_free:
+ free_cpumask_var(mce_dev_initialized);
return err;
}
-
device_initcall(mcheck_init_device);
/*
--
1.7.2.3
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-03-07 10:37 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-04 18:31 [PATCH] x86: mce: Potential memory leaks when initializing mcheck devices Johan Wessfeldt
2011-03-07 6:56 ` Johan Wessfeldt
2011-03-07 10:36 ` [PATCH V2] " Johan Wessfeldt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®