From b87c06483ae805846bfb3ec2594c62ac80f0a8e1 Mon Sep 17 00:00:00 2001
From: David Harton <dharton@cisco.com>
Date: Sat, 3 Feb 2018 09:55:23 -0500
Subject: [PATCH] net/virtio: fix crash while freeing mbufs

virtio_dev_free_mbufs was recently modified to free the
virtqueues but failed to check whether the array was
allocated.  Added a check to ensure vqs was non-null.

Fixes: bdb32afbb610 ("net/virtio: rationalize queue flushing")

Signed-off-by: David Harton <dharton@cisco.com>
Reviewed-by: Olivier Matz <olivier.matz@6wind.com>
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
 drivers/net/virtio/virtio_ethdev.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
index 2082d6adb0..884f74ad04 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -1975,6 +1975,9 @@ static void virtio_dev_free_mbufs(struct rte_eth_dev *dev)
 	struct rte_mbuf *buf;
 	int queue_type;
 
+	if (hw->vqs == NULL)
+		return;
+
 	for (i = 0; i < nr_vq; i++) {
 		vq = hw->vqs[i];
 		if (!vq)