pci: remove redundant pci_dev_get/put() on kobject (un)register
PATCH v2 1/3 pci: remove redundant pci_dev_get/put() on kobject (un)register
Currently we're pci_dev_get/put()-ing pci device on every kobject creation/removal. It's useless per se - the kobject is part of the device itself, so it should be removed when there are no users of the pdev, and is not a user of it.
--- drivers/pci/msi.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/pci/msi.c +1 -5
@@ -511,7 +511,6 @@ static void msi_kobj_release(struct kobject *kobj) {struct msi_desc *entry =to_msi_desc (kobj); -pci_dev_put (entry->dev);kfree (entry); }
@@ -534,13 +533,10 @@ static int populate_msi_sysfs(struct pci_dev *pdev)list_for_each_entry (entry, &pdev->msi_list, list) { kobj = &entry->kobj; kobj->kset = pdev->msi_kset; -pci_dev_get (pdev); ret =kobject_init_and_add (kobj, &msi_irq_ktype,NULL ,"%u" , entry->irq); -if (ret) { -pci_dev_put (pdev); +if (ret)return ret; - } }return 0 ;
Signature · 1 line
1.8.4
PATCH v2 2/3 msi: always unregister ->msi_kset within free_msi_irqs()
Currently we create and populate ->msi_kset while allocating irqs in populate_msi_sysfs(), however if it fails and/or we want to free the entries - we don't always remove it, and we might have problems if we've failed to allocate irqs and try it again.
To fix that, move the unregister part to free_msi_irqs() and remove already existing ones. Also, verify if it was actually created - we don't always call free_msi_irqs() after populate_msi_sysfs().
---
Notes:
v1 -> v2:
Verify if the kset was actually register before unregistering.
drivers/pci/msi.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/pci/msi.c +5 -4
@@ -391,6 +391,11 @@ static void free_msi_irqs(struct pci_dev *dev)kfree (entry); } } + +if (dev->msi_kset) { +kset_unregister (dev->msi_kset); + dev->msi_kset =NULL ; + } }static struct msi_desc *alloc_msi_entry (struct pci_dev *dev)
@@ -904,8 +909,6 @@ void pci_disable_msi(struct pci_dev *dev)pci_msi_shutdown (dev);free_msi_irqs (dev); -kset_unregister (dev->msi_kset); - dev->msi_kset =NULL ; }EXPORT_SYMBOL (pci_disable_msi);
@@ -1002,8 +1005,6 @@ void pci_disable_msix(struct pci_dev *dev)pci_msix_shutdown (dev);free_msi_irqs (dev); -kset_unregister (dev->msi_kset); - dev->msi_kset =NULL ; }EXPORT_SYMBOL (pci_disable_msix);
Signature · 1 line
1.8.4
Re: [PATCH v2 2/3] msi: always unregister ->msi_kset within free_msi_irqs()
Quoted 9 lines · Veaceslav Falico
Currently we create and populate ->msi_kset while allocating irqs in
populate_msi_sysfs(), however if it fails and/or we want to free the entries - we don't always remove it, and we might have problems if we've failed to allocate irqs and try it again.To fix that, move the unregister part to
free_msi_irqs()and remove already existing ones. Also, verify if it was actually created - we don't always callfree_msi_irqs()afterpopulate_msi_sysfs().
Quoted 6 lines
CC Bjorn Helgaas <[email protected]>CC Neil Horman <[email protected]>CC Greg Kroah-Hartman <[email protected]>Signed-off-by Veaceslav Falico <[email protected]>
PATCH v2 3/3 msi: remove useless kobject_del() in free_msi_irqs()
In reply to Veaceslav FalicoWe only need to kobject_put() on removal (which will, eventually, call kobject_del()). kobject_del() should be implicitly used only on circular references (per documentation), however it's not the case here.
--- drivers/pci/msi.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/pci/msi.c +2 -4
@@ -384,12 +384,10 @@ static void free_msi_irqs(struct pci_dev *dev)* kobject->release will take care of freeing the entry via * msi_kobj_release(). */ -if (entry->kobj.parent) { -kobject_del (&entry->kobj); +if (entry->kobj.parent)kobject_put (&entry->kobj); - }else { +else kfree (entry); - } }if (dev->msi_kset) {
Signature · 1 line
1.8.4
Quoted 11 lines · Veaceslav Falico
Currently we're pci_dev_get/put()-ing pci device on every kobject creation/removal. It's useless per se - the kobject is part of the device itself, so it should be removed when there are no users of the pdev, and is not a user of it.
CC Bjorn Helgaas <[email protected]>CC Neil Horman <[email protected]>CC Greg Kroah-Hartman <[email protected]>Signed-off-by Veaceslav Falico <[email protected]>