A device is linked to a driver at probe time.
When detaching, we should call this same driver detach() function and no
need for a driver lookup.

Signed-off-by: David Marchand <david.marchand at 6wind.com>
---
Changes since v1:
- moved some logs for consistency

---
 lib/librte_eal/common/eal_common_pci.c | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_pci.c 
b/lib/librte_eal/common/eal_common_pci.c
index 768421a..082eab8 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -256,13 +256,9 @@ pci_probe_device(struct rte_pci_driver *dr, struct 
rte_pci_device *dev)
  * driver.
  */
 static int
-pci_detach_device(struct rte_pci_driver *dr, struct rte_pci_device *dev)
+pci_detach_device(struct rte_pci_device *dev)
 {
-       struct rte_pci_addr *loc = &dev->addr;
-
-       RTE_LOG(DEBUG, EAL, "PCI device "PCI_PRI_FMT" on NUMA socket %i\n",
-               loc->domain, loc->bus, loc->devid,
-               loc->function, dev->numa_node);
+       struct rte_pci_driver *dr = dev->driver;

        RTE_LOG(DEBUG, EAL, "  remove driver: %x:%x %s\n", dev->id.vendor_id,
                dev->id.device_id, dr->name);
@@ -337,20 +333,19 @@ int
 rte_eal_pci_detach(const struct rte_pci_addr *addr)
 {
        struct rte_pci_device *dev;
-       struct rte_pci_driver *dr;

        if (addr == NULL)
                return -1;

        dev = pci_find_device(addr);
-       if (!dev)
+       if (!dev || !dev->driver)
                goto err_return;

-       dr = pci_find_driver(dev);
-       if (!dr)
-               goto err_return;
+       RTE_LOG(DEBUG, EAL, "PCI device "PCI_PRI_FMT" on NUMA socket %i\n",
+               dev->addr.domain, dev->addr.bus, dev->addr.devid,
+               dev->addr.function, dev->numa_node);

-       if (pci_detach_device(dr, dev) < 0)
+       if (pci_detach_device(dev) < 0)
                goto err_return;

        TAILQ_REMOVE(&pci_device_list, dev, next);
-- 
1.9.1

Reply via email to