net/virtio: fix crash when closing twice
[dpdk.git] / drivers / net / virtio / virtio_ethdev.c
index e79748e..b23f4c2 100644 (file)
@@ -546,6 +546,9 @@ virtio_free_queues(struct virtio_hw *hw)
        int queue_type;
        uint16_t i;
 
+       if (hw->vqs == NULL)
+               return;
+
        for (i = 0; i < nr_vq; i++) {
                vq = hw->vqs[i];
                if (!vq)
@@ -564,9 +567,11 @@ virtio_free_queues(struct virtio_hw *hw)
                }
 
                rte_free(vq);
+               hw->vqs[i] = NULL;
        }
 
        rte_free(hw->vqs);
+       hw->vqs = NULL;
 }
 
 static int
@@ -1348,7 +1353,7 @@ virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features)
        if (virtio_negotiate_features(hw, req_features) < 0)
                return -1;
 
-       if (eth_dev->device) {
+       if (!hw->virtio_user_dev) {
                pci_dev = RTE_DEV_TO_PCI(eth_dev->device);
                rte_eth_copy_pci_info(eth_dev, pci_dev);
        }
@@ -1742,9 +1747,6 @@ virtio_dev_start(struct rte_eth_dev *dev)
                }
        }
 
-       /* Initialize Link state */
-       virtio_dev_link_update(dev, 0);
-
        /*Notify the backend
         *Otherwise the tap backend might already stop its queue due to fullness.
         *vhost backend will have no chance to be waked up
@@ -1773,8 +1775,12 @@ virtio_dev_start(struct rte_eth_dev *dev)
                txvq = dev->data->tx_queues[i];
                VIRTQUEUE_DUMP(txvq->vq);
        }
+
        hw->started = 1;
 
+       /* Initialize Link state */
+       virtio_dev_link_update(dev, 0);
+
        return 0;
 }