[dpdk-dev] [PATCH 3/3] virtio: fix possible NULL dereference

Stephen Hemminger stephen at networkplumber.org
Fri Aug 28 18:23:39 CEST 2015


Found by Coverity. In virtio_dev_queue_release if the queue pointer is
NULL, then driver is dereferencing it to get hw pointer.
Also, don't do useless assignment

Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>
---
 drivers/net/virtio/virtio_ethdev.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
index 338d891..914c73d 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -239,15 +239,15 @@ virtio_set_multiple_queues(struct rte_eth_dev *dev, uint16_t nb_queues)
 
 void
 virtio_dev_queue_release(struct virtqueue *vq) {
-	struct virtio_hw *hw = vq->hw;
 
 	if (vq) {
+		struct virtio_hw *hw = vq->hw;
+
 		/* Select and deactivate the queue */
 		VIRTIO_WRITE_REG_2(hw, VIRTIO_PCI_QUEUE_SEL, vq->queue_id);
 		VIRTIO_WRITE_REG_4(hw, VIRTIO_PCI_QUEUE_PFN, 0);
 
 		rte_free(vq);
-		vq = NULL;
 	}
 }
 
-- 
2.1.4



More information about the dev mailing list