Re: [PATCH] x86/mce: Fix initialization error warning

From: Thomas Gleixner
Date: Mon Jan 16 2017 - 16:57:04 EST


On Mon, 16 Jan 2017, Prarit Bhargava wrote:
> When booting kernel with mce=off a loud warning from the mce code
> is displayed. This causes confusion for end users.
>
> Add a check to see if MCE is available before outputting the warning
> message.

Sigh.

> Signed-off-by: Prarit Bhargava <prarit@xxxxxxxxxx>
> Cc: Tony Luck <tony.luck@xxxxxxxxx>
> Cc: Borislav Petkov <bp@xxxxxxxxx>
> Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
> Cc: Ingo Molnar <mingo@xxxxxxxxxx>
> Cc: "H. Peter Anvin" <hpa@xxxxxxxxx>
> Cc: x86@xxxxxxxxxx
> Cc: linux-edac@xxxxxxxxxxxxxxx
> ---
> arch/x86/kernel/cpu/mcheck/mce.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
> index 00ef43233e03..943a0c440c55 100644
> --- a/arch/x86/kernel/cpu/mcheck/mce.c
> +++ b/arch/x86/kernel/cpu/mcheck/mce.c
> @@ -2662,7 +2662,8 @@ static __init int mcheck_init_device(void)
> free_cpumask_var(mce_device_initialized);
>
> err_out:
> - pr_err("Unable to init device /dev/mcelog (rc: %d)\n", err);
> + if (mce_available(&boot_cpu_data))
> + pr_err("Unable to init device /dev/mcelog (rc: %d)\n", err);

This is really crap. Why would you check the same condition twice? Just
because it's so much more complicated than doing the obvious:

--- a/arch/x86/kernel/cpu/mcheck/mce.c
+++ b/arch/x86/kernel/cpu/mcheck/mce.c
@@ -2615,10 +2615,8 @@ static __init int mcheck_init_device(voi
enum cpuhp_state hp_online;
int err;

- if (!mce_available(&boot_cpu_data)) {
- err = -EIO;
- goto err_out;
- }
+ if (!mce_available(&boot_cpu_data))
+ return -EIO;

if (!zalloc_cpumask_var(&mce_device_initialized, GFP_KERNEL)) {
err = -ENOMEM;