mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] arch/x86/kernel/microcode_core.c: add missing platform_device_unregister
@ 2011-08-24 15:10 Julia Lawall
  2011-08-24 15:36 ` Borislav Petkov
  0 siblings, 1 reply; 4+ messages in thread
From: Julia Lawall @ 2011-08-24 15:10 UTC (permalink / raw)
  To: Tigran Aivazian
  Cc: kernel-janitors, Thomas Gleixner, Ingo Molnar, H. Peter Anvin,
	x86, linux-kernel

From: Julia Lawall <julia@diku.dk>

Call platform_device_unregister as in the previous error-handling code.

Signed-off-by: Julia Lawall <julia@diku.dk>

---
This is not tested, but I couldn't see how else platform_device_unregister
could be called.

 arch/x86/kernel/microcode_core.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
index f924280..1872a3a 100644
--- a/arch/x86/kernel/microcode_core.c
+++ b/arch/x86/kernel/microcode_core.c
@@ -532,8 +532,10 @@ static int __init microcode_init(void)
 	}
 
 	error = microcode_dev_init();
-	if (error)
+	if (error) {
+		platform_device_unregister(microcode_pdev);
 		return error;
+	}
 
 	register_syscore_ops(&mc_syscore_ops);
 	register_hotcpu_notifier(&mc_cpu_notifier);


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

* Re: [PATCH] arch/x86/kernel/microcode_core.c: add missing platform_device_unregister
  2011-08-24 15:10 [PATCH] arch/x86/kernel/microcode_core.c: add missing platform_device_unregister Julia Lawall
@ 2011-08-24 15:36 ` Borislav Petkov
  2011-08-24 15:44   ` Julia Lawall
  0 siblings, 1 reply; 4+ messages in thread
From: Borislav Petkov @ 2011-08-24 15:36 UTC (permalink / raw)
  To: Julia Lawall
  Cc: Tigran Aivazian, kernel-janitors, Thomas Gleixner, Ingo Molnar,
	H. Peter Anvin, x86, linux-kernel

On Wed, Aug 24, 2011 at 05:10:52PM +0200, Julia Lawall wrote:
> From: Julia Lawall <julia@diku.dk>
> 
> Call platform_device_unregister as in the previous error-handling code.
> 
> Signed-off-by: Julia Lawall <julia@diku.dk>
> 
> ---
> This is not tested, but I couldn't see how else platform_device_unregister
> could be called.
> 
>  arch/x86/kernel/microcode_core.c |    4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
> index f924280..1872a3a 100644
> --- a/arch/x86/kernel/microcode_core.c
> +++ b/arch/x86/kernel/microcode_core.c
> @@ -532,8 +532,10 @@ static int __init microcode_init(void)
>  	}
>  
>  	error = microcode_dev_init();
> -	if (error)
> +	if (error) {
> +		platform_device_unregister(microcode_pdev);
>  		return error;
> +	}
>  
>  	register_syscore_ops(&mc_syscore_ops);
>  	register_hotcpu_notifier(&mc_cpu_notifier);

I guess the most sensible thing to do here is to convert this to the
classic goto with labels kernel style:

	...
	error = sysdev_driver_register(..);
	mutex_unlock(&microcode_mutex);
	put_online_cpus();
	if (error)
		goto err_sysdev;

	error = microcode_dev_init();
	if (error)
		goto err_dev;

	...

err_dev:
        get_online_cpus();
        mutex_lock(&microcode_mutex);

        sysdev_driver_unregister(&cpu_sysdev_class, &mc_sysdev_driver);

        mutex_unlock(&microcode_mutex);
        put_online_cpus();


err_sysdev:
	platform_device_unregister(microcode_pdev);

out:
	return err;

or something to that effect.

Thanks.

-- 
Regards/Gruss,
Boris.

Advanced Micro Devices GmbH
Einsteinring 24, 85609 Dornach
GM: Alberto Bozzo
Reg: Dornach, Landkreis Muenchen
HRB Nr. 43632 WEEE Registernr: 129 19551


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

* Re: [PATCH] arch/x86/kernel/microcode_core.c: add missing platform_device_unregister
  2011-08-24 15:36 ` Borislav Petkov
@ 2011-08-24 15:44   ` Julia Lawall
  2011-08-24 16:33     ` Borislav Petkov
  0 siblings, 1 reply; 4+ messages in thread
From: Julia Lawall @ 2011-08-24 15:44 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: Tigran Aivazian, kernel-janitors, Thomas Gleixner, Ingo Molnar,
	H. Peter Anvin, x86, linux-kernel

On Wed, 24 Aug 2011, Borislav Petkov wrote:

> On Wed, Aug 24, 2011 at 05:10:52PM +0200, Julia Lawall wrote:
> > From: Julia Lawall <julia@diku.dk>
> > 
> > Call platform_device_unregister as in the previous error-handling code.
> > 
> > Signed-off-by: Julia Lawall <julia@diku.dk>
> > 
> > ---
> > This is not tested, but I couldn't see how else platform_device_unregister
> > could be called.
> > 
> >  arch/x86/kernel/microcode_core.c |    4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> > 
> > diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
> > index f924280..1872a3a 100644
> > --- a/arch/x86/kernel/microcode_core.c
> > +++ b/arch/x86/kernel/microcode_core.c
> > @@ -532,8 +532,10 @@ static int __init microcode_init(void)
> >  	}
> >  
> >  	error = microcode_dev_init();
> > -	if (error)
> > +	if (error) {
> > +		platform_device_unregister(microcode_pdev);
> >  		return error;
> > +	}
> >  
> >  	register_syscore_ops(&mc_syscore_ops);
> >  	register_hotcpu_notifier(&mc_cpu_notifier);
> 
> I guess the most sensible thing to do here is to convert this to the
> classic goto with labels kernel style:
> 
> 	...
> 	error = sysdev_driver_register(..);
> 	mutex_unlock(&microcode_mutex);
> 	put_online_cpus();
> 	if (error)
> 		goto err_sysdev;
> 
> 	error = microcode_dev_init();
> 	if (error)
> 		goto err_dev;
> 
> 	...
> 
> err_dev:
>         get_online_cpus();
>         mutex_lock(&microcode_mutex);
> 
>         sysdev_driver_unregister(&cpu_sysdev_class, &mc_sysdev_driver);
> 
>         mutex_unlock(&microcode_mutex);
>         put_online_cpus();
> 
> 
> err_sysdev:
> 	platform_device_unregister(microcode_pdev);
> 
> out:
> 	return err;
> 
> or something to that effect.

That seems like a fairly big change.  Is it desirable to move the calls to 
sysdev_driver_register and microcode_dev_init up over the get_online_cpus 
... put_online_cpus sequence?

julia

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

* Re: [PATCH] arch/x86/kernel/microcode_core.c: add missing platform_device_unregister
  2011-08-24 15:44   ` Julia Lawall
@ 2011-08-24 16:33     ` Borislav Petkov
  0 siblings, 0 replies; 4+ messages in thread
From: Borislav Petkov @ 2011-08-24 16:33 UTC (permalink / raw)
  To: Julia Lawall
  Cc: Tigran Aivazian, kernel-janitors, Thomas Gleixner, Ingo Molnar,
	H. Peter Anvin, x86, linux-kernel

On Wed, Aug 24, 2011 at 05:44:08PM +0200, Julia Lawall wrote:
> That seems like a fairly big change.  Is it desirable to move the calls to 
> sysdev_driver_register and microcode_dev_init up over the get_online_cpus 
> ... put_online_cpus sequence?

Well, you need microcode_pdev for request_firmware() which happens
when you do sysdev_driver_register() so it has to run after
platform_device_register_simple().

And the microcode_dev_init() thing got moved further
down in 871b72dd1e12afc3f024479531d25a9339d2e3f9 but its
counterpart microcode_dev_exit() is mistakenly called if
platform_device_register_simple() fails which is clearly another bug.

And frankly, microcode_dev_init() is strictly needed only for the
CONFIG_MICROCODE_OLD_INTERFACE. And on the driver destroy path
microcode_exit() is calling microcode_dev_exit() first so it could be
that 871b72dd1e12afc3f024479531d25a9339d2e3f9 mistakenly moved the
microcode_dev_init() call down.

I guess you could move the microcode_dev_init() call up, before
platform_device_register_simple() but this needs testing on Intel
because they still can do microcode loading over the old interface using
microcode_ctl userspace helper...

Or, you can do a bit cleaner version of the goto-with-labels thing by
adding a helper like this:

static void __microcode_sysdev_unregister(void)
{
        get_online_cpus();
        mutex_lock(&microcode_mutex);

        sysdev_driver_unregister(&cpu_sysdev_class, &mc_sysdev_driver);

        mutex_unlock(&microcode_mutex);
        put_online_cpus();
}

and call it both on the error-out path in microcode_init(), and in
microcode_exit().

Oh boy, the rabbit hole turns out to be pretty deep once you go down
into it :-).

Btw, I totally understand if you've lost all desire to fix that properly
after all this :-).

Thanks.

-- 
Regards/Gruss,
Boris.

Advanced Micro Devices GmbH
Einsteinring 24, 85609 Dornach
GM: Alberto Bozzo
Reg: Dornach, Landkreis Muenchen
HRB Nr. 43632 WEEE Registernr: 129 19551


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

end of thread, other threads:[~2011-08-24 16:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-24 15:10 [PATCH] arch/x86/kernel/microcode_core.c: add missing platform_device_unregister Julia Lawall
2011-08-24 15:36 ` Borislav Petkov
2011-08-24 15:44   ` Julia Lawall
2011-08-24 16:33     ` Borislav Petkov

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®