summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjorn Helgaas <bhelgaas@google.com>2026-02-07 02:09:18 +0300
committerBjorn Helgaas <bhelgaas@google.com>2026-02-07 02:09:18 +0300
commit077557d13f092ebef03f39ba7940e76fce1fd82a (patch)
treef6028bb2e1f1b5a48a598227abbaba87c9fb46e7
parent85fdfc522afd2e81921656853b5f23a1f22984f5 (diff)
parentcba202aa355d2c6297d55c9d5dacceae01266b9c (diff)
downloadlinux-077557d13f092ebef03f39ba7940e76fce1fd82a.tar.xz
Merge branch 'pci/portdrv'
- Drop device reference unconditionally in pcie_port_remove_service() to fix resource leak (Uwe Kleine-König) - Remove empty pcie_port_shutdown_service() callback (Uwe Kleine-König) - Remove unnecessary bus_type check in pcie_port_bus_match() (Uwe Kleine-König) - Move pcie_port_bus_match() and pcie_port_bus_type to PCIe-specific portdrv.c (Uwe Kleine-König) - Remove unnecessary dev and dev->driver checks in portdrv .probe() and .remove() (Uwe Kleine-König) - Take advantage of pcie_port_bus_type.probe() and .remove() instead of assigning them for each portdrv service driver (Uwe Kleine-König) * pci/portdrv: PCI/portdrv: Use bus-type functions PCI/portdrv: Don't check for valid device and driver in bus callbacks PCI/portdrv: Move pcie_port_bus_type to pcie source file PCI/portdrv: Don't check for the driver's and device's bus PCI/portdrv: Drop empty shutdown callback PCI/portdrv: Fix potential resource leak
-rw-r--r--drivers/pci/pci-driver.c28
-rw-r--r--drivers/pci/pcie/portdrv.c55
2 files changed, 28 insertions, 55 deletions
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index 7c2d9d596258..2cc4e9e6f5ef 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -1701,34 +1701,6 @@ const struct bus_type pci_bus_type = {
};
EXPORT_SYMBOL(pci_bus_type);
-#ifdef CONFIG_PCIEPORTBUS
-static int pcie_port_bus_match(struct device *dev, const struct device_driver *drv)
-{
- struct pcie_device *pciedev;
- const struct pcie_port_service_driver *driver;
-
- if (drv->bus != &pcie_port_bus_type || dev->bus != &pcie_port_bus_type)
- return 0;
-
- pciedev = to_pcie_device(dev);
- driver = to_service_driver(drv);
-
- if (driver->service != pciedev->service)
- return 0;
-
- if (driver->port_type != PCIE_ANY_PORT &&
- driver->port_type != pci_pcie_type(pciedev->port))
- return 0;
-
- return 1;
-}
-
-const struct bus_type pcie_port_bus_type = {
- .name = "pci_express",
- .match = pcie_port_bus_match,
-};
-#endif
-
static int __init pci_driver_init(void)
{
int ret;
diff --git a/drivers/pci/pcie/portdrv.c b/drivers/pci/pcie/portdrv.c
index 38a41ccf79b9..88af0dacf351 100644
--- a/drivers/pci/pcie/portdrv.c
+++ b/drivers/pci/pcie/portdrv.c
@@ -508,23 +508,35 @@ static void pcie_port_device_remove(struct pci_dev *dev)
pci_free_irq_vectors(dev);
}
+static int pcie_port_bus_match(struct device *dev, const struct device_driver *drv)
+{
+ struct pcie_device *pciedev = to_pcie_device(dev);
+ const struct pcie_port_service_driver *driver = to_service_driver(drv);
+
+ if (driver->service != pciedev->service)
+ return 0;
+
+ if (driver->port_type != PCIE_ANY_PORT &&
+ driver->port_type != pci_pcie_type(pciedev->port))
+ return 0;
+
+ return 1;
+}
+
/**
- * pcie_port_probe_service - probe driver for given PCI Express port service
+ * pcie_port_bus_probe - probe driver for given PCI Express port service
* @dev: PCI Express port service device to probe against
*
* If PCI Express port service driver is registered with
* pcie_port_service_register(), this function will be called by the driver core
* whenever match is found between the driver and a port service device.
*/
-static int pcie_port_probe_service(struct device *dev)
+static int pcie_port_bus_probe(struct device *dev)
{
struct pcie_device *pciedev;
struct pcie_port_service_driver *driver;
int status;
- if (!dev || !dev->driver)
- return -ENODEV;
-
driver = to_service_driver(dev->driver);
if (!driver || !driver->probe)
return -ENODEV;
@@ -539,7 +551,7 @@ static int pcie_port_probe_service(struct device *dev)
}
/**
- * pcie_port_remove_service - detach driver from given PCI Express port service
+ * pcie_port_bus_remove - detach driver from given PCI Express port service
* @dev: PCI Express port service device to handle
*
* If PCI Express port service driver is registered with
@@ -547,33 +559,25 @@ static int pcie_port_probe_service(struct device *dev)
* when device_unregister() is called for the port service device associated
* with the driver.
*/
-static int pcie_port_remove_service(struct device *dev)
+static void pcie_port_bus_remove(struct device *dev)
{
struct pcie_device *pciedev;
struct pcie_port_service_driver *driver;
- if (!dev || !dev->driver)
- return 0;
-
pciedev = to_pcie_device(dev);
driver = to_service_driver(dev->driver);
- if (driver && driver->remove) {
+ if (driver && driver->remove)
driver->remove(pciedev);
- put_device(dev);
- }
- return 0;
+
+ put_device(dev);
}
-/**
- * pcie_port_shutdown_service - shut down given PCI Express port service
- * @dev: PCI Express port service device to handle
- *
- * If PCI Express port service driver is registered with
- * pcie_port_service_register(), this function will be called by the driver core
- * when device_shutdown() is called for the port service device associated
- * with the driver.
- */
-static void pcie_port_shutdown_service(struct device *dev) {}
+const struct bus_type pcie_port_bus_type = {
+ .name = "pci_express",
+ .match = pcie_port_bus_match,
+ .probe = pcie_port_bus_probe,
+ .remove = pcie_port_bus_remove,
+};
/**
* pcie_port_service_register - register PCI Express port service driver
@@ -586,9 +590,6 @@ int pcie_port_service_register(struct pcie_port_service_driver *new)
new->driver.name = new->name;
new->driver.bus = &pcie_port_bus_type;
- new->driver.probe = pcie_port_probe_service;
- new->driver.remove = pcie_port_remove_service;
- new->driver.shutdown = pcie_port_shutdown_service;
return driver_register(&new->driver);
}