[dpdk-dev,2/5] virtio: check vq parameter in virtqueue_detatch_unused() function
diff mbox

Message ID 1436879459-18400-3-git-send-email-bernard.iremonger@intel.com
State Superseded, archived
Headers show

Commit Message

Iremonger, Bernard July 14, 2015, 1:10 p.m. UTC
If vq is NULL, there is a segmentation fault.

Signed-off-by: Bernard Iremonger <bernard.iremonger@intel.com>
---
 drivers/net/virtio/virtqueue.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

Patch
diff mbox

diff --git a/drivers/net/virtio/virtqueue.c b/drivers/net/virtio/virtqueue.c
index 8a3005f..7f60e3e 100644
--- a/drivers/net/virtio/virtqueue.c
+++ b/drivers/net/virtio/virtqueue.c
@@ -1,7 +1,7 @@ 
 /*-
  *   BSD LICENSE
  *
- *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
  *   All rights reserved.
  *
  *   Redistribution and use in source and binary forms, with or without
@@ -60,11 +60,13 @@  virtqueue_detatch_unused(struct virtqueue *vq)
 	struct rte_mbuf *cookie;
 	int idx;
 
-	for (idx = 0; idx < vq->vq_nentries; idx++) {
-		if ((cookie = vq->vq_descx[idx].cookie) != NULL) {
-			vq->vq_descx[idx].cookie = NULL;
-			return cookie;
+	if (vq != NULL)
+		for (idx = 0; idx < vq->vq_nentries; idx++) {
+			cookie = vq->vq_descx[idx].cookie;
+			if (cookie != NULL) {
+				vq->vq_descx[idx].cookie = NULL;
+				return cookie;
+			}
 		}
-	}
 	return NULL;
 }