* [PATCH] ipmi: Make sure drivers were registered before unregistering them
@ 2010-06-10 17:53 Matthew Garrett
2010-06-10 18:11 ` Corey Minyard
2010-06-14 20:36 ` Andrew Morton
0 siblings, 2 replies; 4+ messages in thread
From: Matthew Garrett @ 2010-06-10 17:53 UTC (permalink / raw)
To: minyard; +Cc: linux-kernel, Matthew Garrett
The ipmi code will never register a PCI or Open Firmware driver if
a hardcoded device is provided by the user. This can cause us to attempt
to unregister a driver that was never registered, resulting in an oops.
Keep track of registration in order to avoid this.
Signed-off-by: Matthew Garrett <mjg@redhat.com>
---
drivers/char/ipmi/ipmi_si_intf.c | 21 +++++++++++++++++----
1 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
index 35603dd..311f85b 100644
--- a/drivers/char/ipmi/ipmi_si_intf.c
+++ b/drivers/char/ipmi/ipmi_si_intf.c
@@ -302,6 +302,12 @@ struct smi_info {
static int force_kipmid[SI_MAX_PARMS];
static int num_force_kipmid;
+#ifdef CONFIG_PCI
+static int pci_registered;
+#endif
+#ifdef CONFIG_PPC_OF
+static int of_registered;
+#endif
static unsigned int kipmid_max_busy_us[SI_MAX_PARMS];
static int num_max_busy_us;
@@ -3314,6 +3320,8 @@ static __devinit int init_ipmi_si(void)
rv = pci_register_driver(&ipmi_pci_driver);
if (rv)
printk(KERN_ERR PFX "Unable to register PCI driver: %d\n", rv);
+ else
+ pci_registered = 1;
#endif
#ifdef CONFIG_ACPI
@@ -3330,6 +3338,7 @@ static __devinit int init_ipmi_si(void)
#ifdef CONFIG_PPC_OF
of_register_platform_driver(&ipmi_of_platform_driver);
+ of_registered = 1;
#endif
/* We prefer devices with interrupts, but in the case of a machine
@@ -3383,11 +3392,13 @@ static __devinit int init_ipmi_si(void)
if (unload_when_empty && list_empty(&smi_infos)) {
mutex_unlock(&smi_infos_lock);
#ifdef CONFIG_PCI
- pci_unregister_driver(&ipmi_pci_driver);
+ if (pci_registered)
+ pci_unregister_driver(&ipmi_pci_driver);
#endif
#ifdef CONFIG_PPC_OF
- of_unregister_platform_driver(&ipmi_of_platform_driver);
+ if (of_registered)
+ of_unregister_platform_driver(&ipmi_of_platform_driver);
#endif
driver_unregister(&ipmi_driver.driver);
printk(KERN_WARNING PFX
@@ -3478,14 +3489,16 @@ static __exit void cleanup_ipmi_si(void)
return;
#ifdef CONFIG_PCI
- pci_unregister_driver(&ipmi_pci_driver);
+ if (pci_registered)
+ pci_unregister_driver(&ipmi_pci_driver);
#endif
#ifdef CONFIG_ACPI
pnp_unregister_driver(&ipmi_pnp_driver);
#endif
#ifdef CONFIG_PPC_OF
- of_unregister_platform_driver(&ipmi_of_platform_driver);
+ if (of_registered)
+ of_unregister_platform_driver(&ipmi_of_platform_driver);
#endif
mutex_lock(&smi_infos_lock);
--
1.7.0.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] ipmi: Make sure drivers were registered before unregistering them
2010-06-10 17:53 [PATCH] ipmi: Make sure drivers were registered before unregistering them Matthew Garrett
@ 2010-06-10 18:11 ` Corey Minyard
2010-06-14 20:36 ` Andrew Morton
1 sibling, 0 replies; 4+ messages in thread
From: Corey Minyard @ 2010-06-10 18:11 UTC (permalink / raw)
To: Matthew Garrett; +Cc: linux-kernel, Andrew Morton
Yes, thanks for this.
Acked-by: Corey Minyard <cminyard@mvista.com>
Matthew Garrett wrote:
> The ipmi code will never register a PCI or Open Firmware driver if
> a hardcoded device is provided by the user. This can cause us to attempt
> to unregister a driver that was never registered, resulting in an oops.
> Keep track of registration in order to avoid this.
>
> Signed-off-by: Matthew Garrett <mjg@redhat.com>
> ---
> drivers/char/ipmi/ipmi_si_intf.c | 21 +++++++++++++++++----
> 1 files changed, 17 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
> index 35603dd..311f85b 100644
> --- a/drivers/char/ipmi/ipmi_si_intf.c
> +++ b/drivers/char/ipmi/ipmi_si_intf.c
> @@ -302,6 +302,12 @@ struct smi_info {
>
> static int force_kipmid[SI_MAX_PARMS];
> static int num_force_kipmid;
> +#ifdef CONFIG_PCI
> +static int pci_registered;
> +#endif
> +#ifdef CONFIG_PPC_OF
> +static int of_registered;
> +#endif
>
> static unsigned int kipmid_max_busy_us[SI_MAX_PARMS];
> static int num_max_busy_us;
> @@ -3314,6 +3320,8 @@ static __devinit int init_ipmi_si(void)
> rv = pci_register_driver(&ipmi_pci_driver);
> if (rv)
> printk(KERN_ERR PFX "Unable to register PCI driver: %d\n", rv);
> + else
> + pci_registered = 1;
> #endif
>
> #ifdef CONFIG_ACPI
> @@ -3330,6 +3338,7 @@ static __devinit int init_ipmi_si(void)
>
> #ifdef CONFIG_PPC_OF
> of_register_platform_driver(&ipmi_of_platform_driver);
> + of_registered = 1;
> #endif
>
> /* We prefer devices with interrupts, but in the case of a machine
> @@ -3383,11 +3392,13 @@ static __devinit int init_ipmi_si(void)
> if (unload_when_empty && list_empty(&smi_infos)) {
> mutex_unlock(&smi_infos_lock);
> #ifdef CONFIG_PCI
> - pci_unregister_driver(&ipmi_pci_driver);
> + if (pci_registered)
> + pci_unregister_driver(&ipmi_pci_driver);
> #endif
>
> #ifdef CONFIG_PPC_OF
> - of_unregister_platform_driver(&ipmi_of_platform_driver);
> + if (of_registered)
> + of_unregister_platform_driver(&ipmi_of_platform_driver);
> #endif
> driver_unregister(&ipmi_driver.driver);
> printk(KERN_WARNING PFX
> @@ -3478,14 +3489,16 @@ static __exit void cleanup_ipmi_si(void)
> return;
>
> #ifdef CONFIG_PCI
> - pci_unregister_driver(&ipmi_pci_driver);
> + if (pci_registered)
> + pci_unregister_driver(&ipmi_pci_driver);
> #endif
> #ifdef CONFIG_ACPI
> pnp_unregister_driver(&ipmi_pnp_driver);
> #endif
>
> #ifdef CONFIG_PPC_OF
> - of_unregister_platform_driver(&ipmi_of_platform_driver);
> + if (of_registered)
> + of_unregister_platform_driver(&ipmi_of_platform_driver);
> #endif
>
> mutex_lock(&smi_infos_lock);
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] ipmi: Make sure drivers were registered before unregistering them
2010-06-10 17:53 [PATCH] ipmi: Make sure drivers were registered before unregistering them Matthew Garrett
2010-06-10 18:11 ` Corey Minyard
@ 2010-06-14 20:36 ` Andrew Morton
2010-06-14 20:47 ` Matthew Garrett
1 sibling, 1 reply; 4+ messages in thread
From: Andrew Morton @ 2010-06-14 20:36 UTC (permalink / raw)
To: Matthew Garrett; +Cc: minyard, linux-kernel
On Thu, 10 Jun 2010 13:53:26 -0400
Matthew Garrett <mjg@redhat.com> wrote:
> The ipmi code will never register a PCI or Open Firmware driver if
> a hardcoded device is provided by the user.
How does a user "provide a hardcoded device"?
> This can cause us to attempt
> to unregister a driver that was never registered, resulting in an oops.
> Keep track of registration in order to avoid this.
>
I tried to work out from the above whether we want to backport this fix
into -stable and failed. And I reckon that if I can't work this out
from a changelog, the changelog is inadequate.
> --- a/drivers/char/ipmi/ipmi_si_intf.c
> +++ b/drivers/char/ipmi/ipmi_si_intf.c
> @@ -302,6 +302,12 @@ struct smi_info {
>
> static int force_kipmid[SI_MAX_PARMS];
> static int num_force_kipmid;
> +#ifdef CONFIG_PCI
> +static int pci_registered;
> +#endif
> +#ifdef CONFIG_PPC_OF
> +static int of_registered;
> +#endif
>
> static unsigned int kipmid_max_busy_us[SI_MAX_PARMS];
> static int num_max_busy_us;
> @@ -3314,6 +3320,8 @@ static __devinit int init_ipmi_si(void)
> rv = pci_register_driver(&ipmi_pci_driver);
> if (rv)
> printk(KERN_ERR PFX "Unable to register PCI driver: %d\n", rv);
> + else
> + pci_registered = 1;
> #endif
>
> #ifdef CONFIG_ACPI
> @@ -3330,6 +3338,7 @@ static __devinit int init_ipmi_si(void)
>
> #ifdef CONFIG_PPC_OF
> of_register_platform_driver(&ipmi_of_platform_driver);
> + of_registered = 1;
I assume the code will still oops if of_register_platform_driver() failed.
> #endif
>
> /* We prefer devices with interrupts, but in the case of a machine
> @@ -3383,11 +3392,13 @@ static __devinit int init_ipmi_si(void)
> if (unload_when_empty && list_empty(&smi_infos)) {
> mutex_unlock(&smi_infos_lock);
> #ifdef CONFIG_PCI
> - pci_unregister_driver(&ipmi_pci_driver);
> + if (pci_registered)
> + pci_unregister_driver(&ipmi_pci_driver);
> #endif
>
> #ifdef CONFIG_PPC_OF
> - of_unregister_platform_driver(&ipmi_of_platform_driver);
> + if (of_registered)
> + of_unregister_platform_driver(&ipmi_of_platform_driver);
> #endif
> driver_unregister(&ipmi_driver.driver);
> printk(KERN_WARNING PFX
> @@ -3478,14 +3489,16 @@ static __exit void cleanup_ipmi_si(void)
> return;
>
> #ifdef CONFIG_PCI
> - pci_unregister_driver(&ipmi_pci_driver);
> + if (pci_registered)
> + pci_unregister_driver(&ipmi_pci_driver);
> #endif
> #ifdef CONFIG_ACPI
> pnp_unregister_driver(&ipmi_pnp_driver);
> #endif
>
> #ifdef CONFIG_PPC_OF
> - of_unregister_platform_driver(&ipmi_of_platform_driver);
> + if (of_registered)
> + of_unregister_platform_driver(&ipmi_of_platform_driver);
> #endif
>
> mutex_lock(&smi_infos_lock);
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] ipmi: Make sure drivers were registered before unregistering them
2010-06-14 20:36 ` Andrew Morton
@ 2010-06-14 20:47 ` Matthew Garrett
0 siblings, 0 replies; 4+ messages in thread
From: Matthew Garrett @ 2010-06-14 20:47 UTC (permalink / raw)
To: Andrew Morton; +Cc: minyard, linux-kernel
On Mon, Jun 14, 2010 at 01:36:08PM -0700, Andrew Morton wrote:
> On Thu, 10 Jun 2010 13:53:26 -0400
> Matthew Garrett <mjg@redhat.com> wrote:
>
> > The ipmi code will never register a PCI or Open Firmware driver if
> > a hardcoded device is provided by the user.
>
> How does a user "provide a hardcoded device"?
By providing device addresses via the module parameters. This is the
terminology used in the driver.
> I tried to work out from the above whether we want to backport this fix
> into -stable and failed. And I reckon that if I can't work this out
> from a changelog, the changelog is inadequate.
We don't. The change that caused this bug was merged post-.34.
> > #ifdef CONFIG_ACPI
> > @@ -3330,6 +3338,7 @@ static __devinit int init_ipmi_si(void)
> >
> > #ifdef CONFIG_PPC_OF
> > of_register_platform_driver(&ipmi_of_platform_driver);
> > + of_registered = 1;
>
> I assume the code will still oops if of_register_platform_driver() failed.
Indeed. I should fix that.
--
Matthew Garrett | mjg59@srcf.ucam.org
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-06-14 20:47 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-10 17:53 [PATCH] ipmi: Make sure drivers were registered before unregistering them Matthew Garrett
2010-06-10 18:11 ` Corey Minyard
2010-06-14 20:36 ` Andrew Morton
2010-06-14 20:47 ` Matthew Garrett
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox