2.6 probe.c "pcibus_class" Device Class, release function
The function release_pcibus_dev() in probe.c defines the release procedure for device class pcibus_class. I want to suggest that this function be scrapped :)
This release function is called in the code path of class_device_unregister(). The pcibus_class devices aren't currently unregistered anywhere, from what I can tell, so this release function is currently unused. The runtime removal of PCI buses from logical partitions on PPC64 requires the unregistration of these class devices. The natural place to do this IMHO is in pci_remove_bus_device() in remove.c.
The problem is that this calls pci_destroy_dev(), which calls put() on the same "bridge" device that the release function does. This should only be done once in the course of removing a pci_bus, and I doubt that we want to changepci_destroy_dev(). The kfree() of the pci_bus struct is also done in bothpci_remove_bus_device() and release_pcibus_dev().
So the only two operations in the release function are redundantly performed in the place where it makes sense to unregister. For these reasons, I think we should scrap the release function altogether and set that pointer in the struct class to NULL.
Thoughts?
John
Quoted 9 lines · John Rose
The function
release_pcibus_dev()inprobe.cdefines the release procedure for device classpcibus_class. I want to suggest that this function be scrapped :)This release function is called in the code path of
class_device_unregister(). Thepcibus_classdevices aren't currently unregistered anywhere, from what I can tell, so this release function is currently unused. The runtime removal of PCI buses from logical partitions on PPC64 requires the unregistration of these class devices. The natural place to do this IMHO is inpci_remove_bus_device()inremove.c.
You're right that the class device isn't currently unregistered, and that was an oversight in the patch I originally sent. Attatched is a patch that remedies that situation. pci_remove_bus_device() *is* the natural place to unregister the class_dev, and that's just what the patch does.
Quoted 5 lines
The problem is that this calls
pci_destroy_dev(), which callsput()on the same "bridge" device that the release function does. This should only be done once in the course of removing apci_bus, and I doubt that we want to changepci_destroy_dev(). Thekfree()of thepci_busstruct is also done in bothpci_remove_bus_device()andrelease_pcibus_dev().
Yep. The patch pulls the kfree() out of pci_remove_bus_device() and calls class_device_unregister() in it's place. This will put() the bridge device and free the pci_bus as needed. put() does need to be called twice because the bridge device is get()'d twice: once when the device is registered and once when it's bus device grabs a reference to it.
Quoted 7 lines
So the only two operations in the release function are redundantly performed in the place where it makes sense to unregister. For these reasons, I think we should scrap the release function altogether and set that pointer in the struct class to NULL.
Thoughts?
John
Disagree, for the reasons above. ;) Patch attatched.
Cheers!
-Matt
drivers/pci/remove.c +1 -1
@@ -83,7 +83,7 @@ void pci_remove_bus_device(struct pci_delist_del (&b->node);spin_unlock (&pci_bus_lock); -kfree (b); +class_device_unregister (&b->class_dev); dev->subordinate =NULL ; }
Quoted 3 lines
put()does need to be
called twice because the bridge device is get()'d twice: once when the device is registered and once when it's bus device grabs a reference to it.
Looks great, thanks Matt.
John
Oops - quick question. Does unregistering blow away the cpuaffinity attr and the bridge symlink?
Thanks-
John
Quoted 7 lines · John Rose
Quoted 3 lines
put()does need to be
called twice because the bridge device is get()'d twice: once when the device is registered and once when it's bus device grabs a reference to it.Looks great, thanks Matt.
John
After testing, it would appear that it does. Perfect! Thanks.
John
Quoted 14 lines · John Rose
Oops - quick question. Does unregistering blow away the cpuaffinity attr and the bridge symlink?
Thanks-
JohnQuoted 7 lines · John Rose
Quoted 3 lines
put()does need to be
called twice because the bridge device is get()'d twice: once when the device is registered and once when it's bus device grabs a reference to it.Looks great, thanks Matt.
John
Quoted 18 lines · Matthew Dobson
Quoted 5 lines · John Rose
The function
release_pcibus_dev()inprobe.cdefines the release procedure for
device classpcibus_class. I want to suggest that this function be scrapped :)Quoted 11 lines
This release function is called in the code path of
class_device_unregister().
Thepcibus_classdevices aren't currently unregistered anywhere, from what I
can tell, so this release function is currently unused. The runtime removal of
PCI buses from logical partitions on PPC64 requires the unregistration of these
class devices. The natural place to do this IMHO is inpci_remove_bus_device()
inremove.c.
Quoted 5 lines
You're right that the class device isn't currently unregistered, and that was an oversight in the patch I originally sent. Attatched is a patch that remedies that situation.
pci_remove_bus_device()*is* the natural place to unregister theclass_dev, and that's just what the patch does.
Thanks, I've applied this patch to my trees and will send off to Linus in the next round of PCI patches.
greg k-h