linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] x86/mce: Improve mcheck_init_device() error handling
@ 2014-05-28  7:12 Mathieu Souchaud
  2014-05-28  9:52 ` Borislav Petkov
  0 siblings, 1 reply; 3+ messages in thread
From: Mathieu Souchaud @ 2014-05-28  7:12 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 by mcheck_init_device().

Signed-off-by: Mathieu Souchaud <mattieu.souchaud@free.fr>
---
 arch/x86/kernel/cpu/mcheck/mce.c |   47 ++++++++++++++++++++++++++++++++------
 1 file changed, 40 insertions(+), 7 deletions(-)

diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
index 68317c8..e361681 100644
--- a/arch/x86/kernel/cpu/mcheck/mce.c
+++ b/arch/x86/kernel/cpu/mcheck/mce.c
@@ -2437,32 +2437,65 @@ 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_device_create;
 		}
 	}
 
-	register_syscore_ops(&mce_syscore_ops);
 	__register_hotcpu_notifier(&mce_cpu_notifier);
 	cpu_notifier_register_done();
 
+	register_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_register;
+
+	return 0;
+
+err_register:
+	unregister_syscore_ops(&mce_syscore_ops);
+
+	cpu_notifier_register_begin();
+	__unregister_hotcpu_notifier(&mce_cpu_notifier);
+	cpu_notifier_register_done();
+
+err_device_create:
+	/*
+	 * We didn't keep track of which devices were created above, but
+	 * even if we had, the set of online cpus might have changed.
+	 * Play safe and remove for every possible cpu, since
+	 * mce_device_remove() will do the right thing.
+	 */
+	for_each_possible_cpu(i)
+		mce_device_remove(i);
+
+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;
 }
-- 
1.7.9.5


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

* Re: [PATCH v3] x86/mce: Improve mcheck_init_device() error handling
  2014-05-28  7:12 [PATCH v3] x86/mce: Improve mcheck_init_device() error handling Mathieu Souchaud
@ 2014-05-28  9:52 ` Borislav Petkov
  2014-05-28 20:50   ` mathieu souchaud
  0 siblings, 1 reply; 3+ messages in thread
From: Borislav Petkov @ 2014-05-28  9:52 UTC (permalink / raw)
  To: Mathieu Souchaud
  Cc: tony.luck, tglx, mingo, hpa, x86, linux-edac, linux-kernel,
	kernel-janitors

On Wed, May 28, 2014 at 09:12:37AM +0200, Mathieu Souchaud wrote:
> Check return code of every function called by mcheck_init_device().
> 
> Signed-off-by: Mathieu Souchaud <mattieu.souchaud@free.fr>

Applied, thanks!

I'll queue it for 3.17 though since we're very close to the 3.16 merge
window and this patch hasn't had any linux-next time.

Thanks for your good work, let me know if you want to do more around mce.

:-)

-- 
Regards/Gruss,
    Boris.

Sent from a fat crate under my desk. Formatting is fine.
--

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

* Re: [PATCH v3] x86/mce: Improve mcheck_init_device() error handling
  2014-05-28  9:52 ` Borislav Petkov
@ 2014-05-28 20:50   ` mathieu souchaud
  0 siblings, 0 replies; 3+ messages in thread
From: mathieu souchaud @ 2014-05-28 20:50 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: tony.luck, tglx, mingo, hpa, x86, linux-edac, linux-kernel,
	kernel-janitors

Thanks too, you helped me a lot.

I can do more work, if it's not too difficult for me.

Mathieu

Le 28/05/2014 11:52, Borislav Petkov a écrit :
> On Wed, May 28, 2014 at 09:12:37AM +0200, Mathieu Souchaud wrote:
>> Check return code of every function called by mcheck_init_device().
>>
>> Signed-off-by: Mathieu Souchaud <mattieu.souchaud@free.fr>
> Applied, thanks!
>
> I'll queue it for 3.17 though since we're very close to the 3.16 merge
> window and this patch hasn't had any linux-next time.
>
> Thanks for your good work, let me know if you want to do more around mce.
>
> :-)
>


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

end of thread, other threads:[~2014-05-28 20:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-28  7:12 [PATCH v3] x86/mce: Improve mcheck_init_device() error handling Mathieu Souchaud
2014-05-28  9:52 ` Borislav Petkov
2014-05-28 20:50   ` mathieu souchaud

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).