Re: [PATCH v2 07/11] ACPI: acpi_pci_unbind should clean upproperly after acpi_pci_bind

From: Alex Chiang
Date: Tue Jun 09 2009 - 15:09:29 EST


* Kenji Kaneshige <kaneshige.kenji@xxxxxxxxxxxxxx>:
> Alex Chiang wrote:
>> diff --git a/drivers/acpi/pci_bind.c b/drivers/acpi/pci_bind.c
>> index 62cb383..c9cc650 100644
>> --- a/drivers/acpi/pci_bind.c
>> +++ b/drivers/acpi/pci_bind.c
>> @@ -109,11 +109,13 @@ static int acpi_pci_unbind(struct acpi_device *device)
>> struct pci_dev *dev;
>> dev = acpi_get_pci_dev(device->handle);
>> - if (!dev)
>> + if (!dev || !dev->subordinate)
>> return 0;
>
> This would leak the pci_dev's refcount
> if dev != NULL && dev->subordinate == NULL.

Yes, of course you are correct. Thanks for correcting my
sloppiness.

Here is the correct fix.

From: Alex Chiang <achiang@xxxxxx>

ACPI: acpi_pci_unbind should clean up properly after acpi_pci_bind

In acpi_pci_bind, we set device->ops.bind and device->ops.unbind, but
never clear them out.

Cc: Bjorn Helgaas <bjorn.helgaas@xxxxxx>
Signed-off-by: Alex Chiang <achiang@xxxxxx>
---
diff --git a/drivers/acpi/pci_bind.c b/drivers/acpi/pci_bind.c
index 62cb383..af75784 100644
--- a/drivers/acpi/pci_bind.c
+++ b/drivers/acpi/pci_bind.c
@@ -109,12 +109,15 @@ static int acpi_pci_unbind(struct acpi_device *device)
struct pci_dev *dev;

dev = acpi_get_pci_dev(device->handle);
- if (!dev)
- return 0;
+ if (!dev || !dev->subordinate)
+ goto out:

- if (dev->subordinate)
- acpi_pci_irq_del_prt(dev->subordinate);
+ acpi_pci_irq_del_prt(dev->subordinate);

+ device->ops.bind = NULL;
+ device->ops.unbind = NULL;
+
+out:
pci_dev_put(dev);
return 0;
}
--
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/