summaryrefslogtreecommitdiff
path: root/drivers/net/virtio/virtio_ethdev.c
diff options
context:
space:
mode:
authorOlivier Matz <olivier.matz@6wind.com>2018-01-23 16:54:41 +0100
committerFerruh Yigit <ferruh.yigit@intel.com>2018-01-29 10:04:28 +0100
commit3669a1af893088064778f14fba0c2ca88819e095 (patch)
treeb8abf7be4f1fcfbd40ff2a4ffb02785e8b95552d /drivers/net/virtio/virtio_ethdev.c
parente67ae1e27e27b0fce9974dbf1b5bc6adff27a213 (diff)
downloaddpdk-next-eventdev-3669a1af893088064778f14fba0c2ca88819e095.zip
dpdk-next-eventdev-3669a1af893088064778f14fba0c2ca88819e095.tar.gz
dpdk-next-eventdev-3669a1af893088064778f14fba0c2ca88819e095.tar.xz
net/virtio: fix memory leak when reinitializing device
Free the previous queues and the attached mbufs before initializing new ones. The function virtio_dev_free_mbufs() is now called when reconfiguring the device, so we also need to add a check to ensure that it won't crash for uninitialized queues. Cc: stable@dpdk.org Fixes: 60e6f4707ef2 ("net/virtio: reinitialize device when configuring") Signed-off-by: Zijie Pan <zijie.pan@6wind.com> Signed-off-by: Olivier Matz <olivier.matz@6wind.com> Acked-by: Yuanhan Liu <yliu@fridaylinux.org>
Diffstat (limited to 'drivers/net/virtio/virtio_ethdev.c')
-rw-r--r--drivers/net/virtio/virtio_ethdev.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
index 6e79a26..4f20e47 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -1471,6 +1471,11 @@ virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features)
/* Reset the device although not necessary at startup */
vtpci_reset(hw);
+ if (hw->vqs) {
+ virtio_dev_free_mbufs(eth_dev);
+ virtio_free_queues(hw);
+ }
+
/* Tell the host we've noticed this device. */
vtpci_set_status(hw, VIRTIO_CONFIG_STATUS_ACK);
@@ -1968,6 +1973,9 @@ static void virtio_dev_free_mbufs(struct rte_eth_dev *dev)
for (i = 0; i < dev->data->nb_rx_queues; i++) {
struct virtnet_rx *rxvq = dev->data->rx_queues[i];
+ if (rxvq == NULL || rxvq->vq == NULL)
+ continue;
+
PMD_INIT_LOG(DEBUG,
"Before freeing rxq[%d] used and unused buf", i);
VIRTQUEUE_DUMP(rxvq->vq);
@@ -1987,6 +1995,9 @@ static void virtio_dev_free_mbufs(struct rte_eth_dev *dev)
for (i = 0; i < dev->data->nb_tx_queues; i++) {
struct virtnet_tx *txvq = dev->data->tx_queues[i];
+ if (txvq == NULL || txvq->vq == NULL)
+ continue;
+
PMD_INIT_LOG(DEBUG,
"Before freeing txq[%d] used and unused bufs",
i);