[PATCH] ACPI: some issues managing the linked list inacpi_pci_register/unregister_driver

From: james puthukattukaran - Sun Microsystems - Burlington United States
Date: Wed Aug 05 2009 - 18:10:25 EST


I submitted an earlier patch on this to lkml with just a single line initializing the sub_driver variable to NULL. This was insufficient. This patch fixes some link list management issues in adding a new acpi_pci_driver type to the sub_driver list. This is against 2.6.30

Signed-off-by: James Puthukattukaran <james.puthukattukaran@xxxxxxx>

--- linux-2.6.30/drivers/acpi/pci_root.c.orig 2009-08-05 12:56:01.000000000 -0400
+++ linux-2.6.30/drivers/acpi/pci_root.c 2009-08-05 14:28:01.000000000 -0400
@@ -76,7 +76,7 @@ struct acpi_pci_root {

static LIST_HEAD(acpi_pci_roots);

-static struct acpi_pci_driver *sub_driver;
+static struct acpi_pci_driver *sub_driver = NULL;
static DEFINE_MUTEX(osc_lock);

int acpi_pci_register_driver(struct acpi_pci_driver *driver)
@@ -84,10 +84,9 @@ int acpi_pci_register_driver(struct acpi
int n = 0;
struct list_head *entry;

- struct acpi_pci_driver **pptr = &sub_driver;
- while (*pptr)
- pptr = &(*pptr)->next;
- *pptr = driver;
+ /* Add to the head of the list */
+ driver->next = sub_driver;
+ sub_driver = driver;

if (!driver->add)
return 0;
@@ -107,15 +106,21 @@ EXPORT_SYMBOL(acpi_pci_register_driver);
void acpi_pci_unregister_driver(struct acpi_pci_driver *driver)
{
struct list_head *entry;
+ struct acpi_pci_driver *pptr, *prev;

- struct acpi_pci_driver **pptr = &sub_driver;
- while (*pptr) {
- if (*pptr == driver)
+ /* Remove driver from the sub_driver list */
+ for (prev = NULL, pptr = sub_driver; pptr;
+ prev = pptr, pptr=pptr->next)
+ {
+ if (pptr == driver) {
+ if (!prev)
+ sub_driver = driver->next;
+ else
+ prev->next = pptr->next;
break;
- pptr = &(*pptr)->next;
+ }
}
- BUG_ON(!*pptr);
- *pptr = (*pptr)->next;
+ BUG_ON(!pptr);

if (!driver->remove)
return;
--
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/