Re: [PATCH v2 02/13] PCI: prevent duplicate slot names

From: Alex Chiang
Date: Thu Sep 11 2008 - 06:38:41 EST


* Kenji Kaneshige <kaneshige.kenji@xxxxxxxxxxxxxx>:
> Alex Chiang wrote:
>> @@ -570,9 +571,17 @@ int pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus, int slot_nr,
>> return -EINVAL;
>> }
>> - /* Check if we have already registered a slot with the same name. */
>> - if (get_slot_from_name(name))
>> - return -EEXIST;
>> + /*
>> + * If we find a tmp_slot here, it means that another slot
>> + * driver has already created a pci_slot for this device.
>> + * We care (below) if the existing slot has a different name from
>> + * the new name that this particular hotplug driver is requesting.
>> + */
>> + dev = pci_get_slot(bus, PCI_DEVFN(slot_nr, 0));
>> + if (dev && dev->slot) {
>> + tmp_slot = dev->slot;
>> + pci_dev_put(dev);
>> + }
>>
>
> I have two comments here.
>
> (1) I think the reference counter of the device will be leaked if
> (dev == NULL) && (dev->slot != NULL). We need pci_dev_put() whenever
> dev is not NULL.

You're right, thank you.

[one day, I _will_ learn how to get refcounting correct. :-/]

> (2) When the slot is empty, the 'dev' will be always NULL. Therefore,
> 'tmp_slot' will be always NULL on the empty slot here. Because of
> this, the following code to rename the slot will not work on the
> empty slot, I think.

Ok, I was trying to avoid creating a new interface called
"pci_find_phys_slot()" or something similar, but I think we need
it, and it will fix this issue.

Thanks again for the review.

/ac

--
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/