Skip to contentSkip to conversation

examples/vhost: fix unchecked return value

PATCH Applied Chenbo Xia 2 participants 3 messages Feb 19, 2021 – Mar 31, 2021

lore
Share & tools
lore

Chenbo Xia

author
#0 lore raw

PATCH 1/1 examples/vhost: fix unchecked return value

This patch fixes unchecked return value for rte_vhost_get_mem_table(), which is reported by coverity.

Coverity issue: 364233

Fixes ca059fa5e290 ("examples/vhost: demonstrate the new generic APIs")
---
 examples/vhost/virtio_net.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
examples/vhost/virtio_net.c +7 -1
index 64bf3d19ff..9064fc3a82 100644
@@ -23,6 +23,7 @@ vs_vhost_net_setup(struct vhost_dev *dev)
 	uint16_t i;
 	int vid = dev->vid;
 	struct vhost_queue *queue;
+	int ret;
 
 	RTE_LOG(INFO, VHOST_CONFIG,
 		"setting builtin vhost-user net driver\n");
@@ -33,7 +34,12 @@ vs_vhost_net_setup(struct vhost_dev *dev)
 	else
 		dev->hdr_len = sizeof(struct virtio_net_hdr);
 
-	rte_vhost_get_mem_table(vid, &dev->mem);
+	ret = rte_vhost_get_mem_table(vid, &dev->mem);
+	if (ret < 0) {
+		RTE_LOG(ERR, VHOST_CONFIG, "Failed to get "
+			"VM memory layout for device(%d)\n", vid);
+		return;
+	}
 
 	dev->nr_vrings = rte_vhost_get_vring_num(vid);
 	for (i = 0; i < dev->nr_vrings; i++) {
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 29 lines · Chenbo Xia

This patch fixes unchecked return value for rte_vhost_get_mem_table(), which is reported by coverity.

Coverity issue: 364233

Fixes ca059fa5e290 ("examples/vhost: demonstrate the new generic APIs")
---
 examples/vhost/virtio_net.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
examples/vhost/virtio_net.c +1 -0
index 64bf3d19ff..9064fc3a82 100644
@@ -23,6 +23,7 @@ vs_vhost_net_setup(struct vhost_dev *dev)
 	uint16_t i;
 	int vid = dev->vid;
 	struct vhost_queue *queue;
+	int ret;
 
 	RTE_LOG(INFO, VHOST_CONFIG,
 		"setting builtin vhost-user net driver\n");
@@ -33,7 +34,12 @@ vs_vhost_net_setup(struct vhost_dev *dev)
 	else
 		dev->hdr_len = sizeof(struct virtio_net_hdr);
 

examples/vhost/virtio_net.c vs_vhost_net_setup(struct vhost_dev *dev) · line 45

Quoted 10 lines
examples/vhost/virtio_net.c +6 -1
-	rte_vhost_get_mem_table(vid, &dev->mem);
+	ret = rte_vhost_get_mem_table(vid, &dev->mem);
+	if (ret < 0) {
+		RTE_LOG(ERR, VHOST_CONFIG, "Failed to get "
+			"VM memory layout for device(%d)\n", vid);
+		return;
+	}
 
 	dev->nr_vrings = rte_vhost_get_vring_num(vid);
 	for (i = 0; i < dev->nr_vrings; i++) {

Thanks,
Maxime

author Applied
#2 lore raw
In reply to Chenbo Xia
Quoted 10 lines

-----Original Message-----
From: dev <[email protected]> On Behalf Of Chenbo Xia
Sent: Friday, February 19, 2021 10:40 AM
To: [email protected]
Cc: [email protected]; [email protected]
Subject: [dpdk-dev] [PATCH] examples/vhost: fix unchecked return value

This patch fixes unchecked return value for rte_vhost_get_mem_table(), which is reported by coverity.

Quoted 7 lines

Coverity issue: 364233

Fixes ca059fa5e290 ("examples/vhost: demonstrate the new generic APIs")

---
2.17.1

Applied to next-virtio/main, Thanks