Skip to content

Commit 4acc902

Browse files
zijun-hukwilczynski
authored andcommitted
PCI: endpoint: Fix PCI domain ID release in pci_epc_destroy()
pci_epc_destroy() invokes pci_bus_release_domain_nr() to release the PCI domain ID, but there are two issues: - 'epc->dev' is passed to pci_bus_release_domain_nr() which was already freed by device_unregister(), leading to a use-after-free issue. - Domain ID corresponds to the EPC device parent, so passing 'epc->dev' is also wrong. Fix these issues by passing 'epc->dev.parent' to pci_bus_release_domain_nr() and also do it before device_unregister(). Fixes: 0328947 ("PCI: endpoint: Assign PCI domain number for endpoint controllers") Signed-off-by: Zijun Hu <[email protected]> Reviewed-by: Manivannan Sadhasivam <[email protected]> Link: https://lore.kernel.org/r/[email protected] [mani: reworded subject and description] Signed-off-by: Manivannan Sadhasivam <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]> Signed-off-by: Krzysztof Wilczyński <[email protected]> Cc: [email protected]
1 parent 5089b3d commit 4acc902

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

drivers/pci/endpoint/pci-epc-core.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -923,11 +923,10 @@ EXPORT_SYMBOL_GPL(pci_epc_bus_master_enable_notify);
923923
void pci_epc_destroy(struct pci_epc *epc)
924924
{
925925
pci_ep_cfs_remove_epc_group(epc->group);
926-
device_unregister(&epc->dev);
927-
928926
#ifdef CONFIG_PCI_DOMAINS_GENERIC
929-
pci_bus_release_domain_nr(&epc->dev, epc->domain_nr);
927+
pci_bus_release_domain_nr(epc->dev.parent, epc->domain_nr);
930928
#endif
929+
device_unregister(&epc->dev);
931930
}
932931
EXPORT_SYMBOL_GPL(pci_epc_destroy);
933932

0 commit comments

Comments
 (0)