mirror of
https://github.com/torvalds/linux.git
synced 2026-03-08 03:04:51 +01:00
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
This commit is contained in:
commit
077557d13f
2 changed files with 28 additions and 55 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue