* [PATCH] x86/mce: Improve mcheck_init_device() error handling.
@ 2014-04-25 17:40 Mathieu Souchaud
2014-04-25 17:47 ` mathieu souchaud
2014-04-28 19:36 ` Borislav Petkov
0 siblings, 2 replies; 3+ messages in thread
From: Mathieu Souchaud @ 2014-04-25 17:40 UTC (permalink / raw)
To: tony.luck, bp, tglx, mingo, hpa, x86, linux-edac, linux-kernel,
kernel-janitors
Cc: Mathieu Souchaud
Check return code of every function called.
Signed-off-by: Mathieu Souchaud <mattieu.souchaud@free.fr>
---
arch/x86/kernel/cpu/mcheck/mce.c | 30 +++++++++++++++++++++++-------
1 file changed, 23 insertions(+), 7 deletions(-)
diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
index 68317c8..b865285 100644
--- a/arch/x86/kernel/cpu/mcheck/mce.c
+++ b/arch/x86/kernel/cpu/mcheck/mce.c
@@ -2437,33 +2437,49 @@ 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 err_out;
+ }
- zalloc_cpumask_var(&mce_device_initialized, GFP_KERNEL);
+ if (!zalloc_cpumask_var(&mce_device_initialized, GFP_KERNEL)) {
+ err = -ENOMEM;
+ goto err_out;
+ }
mce_init_banks();
err = subsys_system_register(&mce_subsys, NULL);
if (err)
- return err;
+ goto err_out_mem;
cpu_notifier_register_begin();
for_each_online_cpu(i) {
err = mce_device_create(i);
if (err) {
cpu_notifier_register_done();
- return err;
+ goto err_out_mem;
}
}
register_syscore_ops(&mce_syscore_ops);
- __register_hotcpu_notifier(&mce_cpu_notifier);
+ err = __register_hotcpu_notifier(&mce_cpu_notifier);
cpu_notifier_register_done();
+ if (err)
+ goto err_out_mem;
/* register character device /dev/mcelog */
- misc_register(&mce_chrdev_device);
+ err = misc_register(&mce_chrdev_device);
+ if (err)
+ goto err_out_mem;
+
+ return 0;
+
+err_out_mem:
+ free_cpumask_var(mce_device_initialized);
+err_out:
+ pr_err("Unable to init device /dev/mcelog (rc: %d)\n", err);
return err;
}
device_initcall_sync(mcheck_init_device);
--
1.7.9.5
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] x86/mce: Improve mcheck_init_device() error handling.
2014-04-25 17:40 [PATCH] x86/mce: Improve mcheck_init_device() error handling Mathieu Souchaud
@ 2014-04-25 17:47 ` mathieu souchaud
2014-04-28 19:36 ` Borislav Petkov
1 sibling, 0 replies; 3+ messages in thread
From: mathieu souchaud @ 2014-04-25 17:47 UTC (permalink / raw)
To: tony.luck, bp, tglx, mingo, hpa, x86, linux-edac, linux-kernel,
kernel-janitors
In this patch, unwindind is still not perfect from the
mce_device_create() calls. I guess, from this point, on error we should
call mce_device_remove on every created device. But I think this will
make the code rather complex. And I am not too confident on this kind of
modification as I don't know much about MCE.
Mathieu S.
Le 25/04/2014 19:40, Mathieu Souchaud a écrit :
> Check return code of every function called.
>
> Signed-off-by: Mathieu Souchaud <mattieu.souchaud@free.fr>
> ---
> arch/x86/kernel/cpu/mcheck/mce.c | 30 +++++++++++++++++++++++-------
> 1 file changed, 23 insertions(+), 7 deletions(-)
>
> diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
> index 68317c8..b865285 100644
> --- a/arch/x86/kernel/cpu/mcheck/mce.c
> +++ b/arch/x86/kernel/cpu/mcheck/mce.c
> @@ -2437,33 +2437,49 @@ 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 err_out;
> + }
>
> - zalloc_cpumask_var(&mce_device_initialized, GFP_KERNEL);
> + if (!zalloc_cpumask_var(&mce_device_initialized, GFP_KERNEL)) {
> + err = -ENOMEM;
> + goto err_out;
> + }
>
> mce_init_banks();
>
> err = subsys_system_register(&mce_subsys, NULL);
> if (err)
> - return err;
> + goto err_out_mem;
>
> cpu_notifier_register_begin();
> for_each_online_cpu(i) {
> err = mce_device_create(i);
> if (err) {
> cpu_notifier_register_done();
> - return err;
> + goto err_out_mem;
> }
> }
>
> register_syscore_ops(&mce_syscore_ops);
> - __register_hotcpu_notifier(&mce_cpu_notifier);
> + err = __register_hotcpu_notifier(&mce_cpu_notifier);
> cpu_notifier_register_done();
> + if (err)
> + goto err_out_mem;
>
> /* register character device /dev/mcelog */
> - misc_register(&mce_chrdev_device);
> + err = misc_register(&mce_chrdev_device);
> + if (err)
> + goto err_out_mem;
> +
> + return 0;
> +
> +err_out_mem:
> + free_cpumask_var(mce_device_initialized);
>
> +err_out:
> + pr_err("Unable to init device /dev/mcelog (rc: %d)\n", err);
> return err;
> }
> device_initcall_sync(mcheck_init_device);
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] x86/mce: Improve mcheck_init_device() error handling.
2014-04-25 17:40 [PATCH] x86/mce: Improve mcheck_init_device() error handling Mathieu Souchaud
2014-04-25 17:47 ` mathieu souchaud
@ 2014-04-28 19:36 ` Borislav Petkov
1 sibling, 0 replies; 3+ messages in thread
From: Borislav Petkov @ 2014-04-28 19:36 UTC (permalink / raw)
To: Mathieu Souchaud
Cc: tony.luck, tglx, mingo, hpa, x86, linux-edac, linux-kernel,
kernel-janitors
On Fri, Apr 25, 2014 at 07:40:04PM +0200, Mathieu Souchaud wrote:
> Check return code of every function called.
>
> Signed-off-by: Mathieu Souchaud <mattieu.souchaud@free.fr>
> ---
> arch/x86/kernel/cpu/mcheck/mce.c | 30 +++++++++++++++++++++++-------
> 1 file changed, 23 insertions(+), 7 deletions(-)
>
> diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
> index 68317c8..b865285 100644
> --- a/arch/x86/kernel/cpu/mcheck/mce.c
> +++ b/arch/x86/kernel/cpu/mcheck/mce.c
> @@ -2437,33 +2437,49 @@ 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 err_out;
> + }
>
> - zalloc_cpumask_var(&mce_device_initialized, GFP_KERNEL);
> + if (!zalloc_cpumask_var(&mce_device_initialized, GFP_KERNEL)) {
> + err = -ENOMEM;
> + goto err_out;
> + }
>
> mce_init_banks();
>
> err = subsys_system_register(&mce_subsys, NULL);
> if (err)
> - return err;
> + goto err_out_mem;
>
> cpu_notifier_register_begin();
> for_each_online_cpu(i) {
> err = mce_device_create(i);
> if (err) {
> cpu_notifier_register_done();
> - return err;
> + goto err_out_mem;
Actually, this should partially unwind what has been created already,
like this:
if (err)
goto err_device_create;
and then at that label, you can do:
err_device_create:
while (--i > 0)
mce_device_remove(i);
cpu_notifier_register_done();
And then here come your other labels:
err_out_mem:
....
And so on. Makes sense?
> register_syscore_ops(&mce_syscore_ops);
> - __register_hotcpu_notifier(&mce_cpu_notifier);
> + err = __register_hotcpu_notifier(&mce_cpu_notifier);
> cpu_notifier_register_done();
> + if (err)
> + goto err_out_mem;
This needs to be a label which goes before err_device_create above and
which does
err_reg_hotcpu:
unregister_syscore_ops(&mce_syscore_ops);
>
> /* register character device /dev/mcelog */
> - misc_register(&mce_chrdev_device);
> + err = misc_register(&mce_chrdev_device);
> + if (err)
> + goto err_out_mem;
And this has to go to the top-label which unwinds all the work, along
with the mce percpu devices like:
for_each_online_cpu(i)
mce_device_remove(i);
unregister_hotcpu_notifier(&mce_cpu_notifier);
...
and so on.
Ok, am I making sense?
Don't be afraid to give it a try, even if it is wrong - we'll get it
right eventually :-)
For testing, you can use a kvm guest and "inject" errors in the
registration code just to see whether it works as expected.
And feel free to ask questions if something's not clear.
Thanks!
--
Regards/Gruss,
Boris.
Sent from a fat crate under my desk. Formatting is fine.
--
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-04-28 19:36 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-25 17:40 [PATCH] x86/mce: Improve mcheck_init_device() error handling Mathieu Souchaud
2014-04-25 17:47 ` mathieu souchaud
2014-04-28 19:36 ` Borislav Petkov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox