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

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Kenji Kaneshige
Date: Thursday, August 21, 2008 - 3:24 am

Hi Alex-san,

Thank you for updated patches and I'm sorry for delayed comment.
I reviewed your patch and I found two problems. Please see below.

Alex Chiang wrote:

The kset_find_obj() increments reference counter of specified kobject. So
we must call kobject_put() for 'dup_slot', otherwise it leaks reference
counter of 'dup_slot' kobject and the corresponding slot directory will
never be removed. Here is a sample to fix this problem.

	dup_slot = kset_find_ojb(pci_slots_kset, new_name);
	if (!dup_slot)
		goto out;
	kobject_put(dup_slot);
	^^^^^^^^^^^^^^^^^^^^^^ Added this line


I found another problem in pci_hp_register() that would be more complex
to fix than above-mentioned problem. Here is a pci_hp_register() with
all of your patch applied.

int pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus, int slot_nr,
                        const char *name)
{
	(snip...)

        /*
         * No problems if we call this interface from both ACPI_PCI_SLOT
         * driver and call it here again. If we've already created the
         * pci_slot, the interface will simply bump the refcount.
         */
        pci_slot = pci_create_slot(bus, slot_nr, name);
        if (IS_ERR(pci_slot))
                return PTR_ERR(pci_slot);

        if (pci_slot->hotplug) {
                dbg("%s: already claimed\n", __func__);
                pci_destroy_slot(pci_slot);
                return -EBUSY;
        }

        slot->pci_slot = pci_slot;
        pci_slot->hotplug = slot;

        /*
         * Allow pcihp drivers to override the ACPI_PCI_SLOT name.
         */
        if (strcmp(kobject_name(&pci_slot->kobj), name)) {
                result = kobject_rename(&pci_slot->kobj, name);
                if (result) {
                        pci_destroy_slot(pci_slot);
                        return result;
                }
        }

	(snip...)
}

If name duplication was detected in pci_create_slot(), it renames the
slot name like 'N-1' and return successfully. Even though slot's kobject
name was registered as 'N-1', 'name' array still have 'N' at this point.
So the following 'if' statement becomes true unexpectedly.

	/*
         * Allow pcihp drivers to override the ACPI_PCI_SLOT name.
         */
        if (strcmp(kobject_name(&pci_slot->kobj), name)) {

Then pci_hp_register() attempt to rename the slot name with 'N' again
by calling kobject_rename(), but it fails because there already exists
kobject with name 'N'. As a result, pci_hp_register() will fail.

Thanks,
Kenji Kaneshige


--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 00/13] PCI: let the core manage slot names, Alex Chiang, (Sat Aug 16, 5:14 pm)
[PATCH 02/13] PCI: prevent duplicate slot names, Alex Chiang, (Sat Aug 16, 5:16 pm)
[PATCH 04/13] PCI: acpiphp: remove 'name' parameter, Alex Chiang, (Sat Aug 16, 5:16 pm)
[PATCH 07/13] PCI: fakephp: remove 'name' parameter, Alex Chiang, (Sat Aug 16, 5:17 pm)
[PATCH 09/13] PCI: pciehp: remove 'name' parameter, Alex Chiang, (Sat Aug 16, 5:17 pm)
[PATCH 12/13] PCI: shcphp: remove 'name' parameter, Alex Chiang, (Sat Aug 16, 5:17 pm)
[PATCH 13/13] PCI: Hotplug core: remove 'name', Alex Chiang, (Sat Aug 16, 5:17 pm)
Re: [PATCH 04/13] PCI: acpiphp: remove 'name' parameter, Rolf Eike Beer, (Sun Aug 17, 1:59 am)
Re: [PATCH 04/13] PCI: acpiphp: remove 'name' parameter, Alex Chiang, (Tue Aug 19, 11:39 am)
Re: [PATCH 04/13] PCI: acpiphp: remove 'name' parameter, Rolf Eike Beer, (Tue Aug 19, 2:01 pm)
Re: [PATCH 04/13] PCI: acpiphp: remove 'name' parameter, Jesse Barnes, (Tue Aug 19, 2:40 pm)
Re: [PATCH 04/13] PCI: acpiphp: remove 'name' parameter, Kenji Kaneshige, (Tue Aug 19, 7:25 pm)
Re: [PATCH 02/13] PCI: prevent duplicate slot names, Kenji Kaneshige, (Thu Aug 21, 3:24 am)
Re: [PATCH 02/13] PCI: prevent duplicate slot names, Alex Chiang, (Tue Sep 9, 2:04 am)
Re: [PATCH 02/13] PCI: prevent duplicate slot names, Kenji Kaneshige, (Wed Sep 10, 7:43 pm)