diff mbox series

examples/vhost: fix unchecked return value

Message ID 20210219024011.77233-1-chenbo.xia@intel.com (mailing list archive)
State Accepted
Delegated to: Maxime Coquelin
Headers show
Series examples/vhost: fix unchecked return value | expand

Checks

Context Check Description
ci/intel-Testing success Testing PASS
ci/iol-testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/github-robot success github build: passed
ci/travis-robot fail travis build: failed
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/Intel-compilation success Compilation OK
ci/checkpatch success coding style OK

Commit Message

Xia, Chenbo Feb. 19, 2021, 2:40 a.m. UTC
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")
Cc: stable@dpdk.org

Signed-off-by: Chenbo Xia <chenbo.xia@intel.com>
---
 examples/vhost/virtio_net.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Comments

Maxime Coquelin March 19, 2021, 9:50 a.m. UTC | #1
On 2/19/21 3:40 AM, Chenbo Xia wrote:
> 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")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Chenbo Xia <chenbo.xia@intel.com>
> ---
>  examples/vhost/virtio_net.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/examples/vhost/virtio_net.c b/examples/vhost/virtio_net.c
> index 64bf3d19ff..9064fc3a82 100644
> --- a/examples/vhost/virtio_net.c
> +++ b/examples/vhost/virtio_net.c
> @@ -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++) {
> 

Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>

Thanks,
Maxime
Xia, Chenbo March 31, 2021, 6:56 a.m. UTC | #2
> -----Original Message-----
> From: dev <dev-bounces@dpdk.org> On Behalf Of Chenbo Xia
> Sent: Friday, February 19, 2021 10:40 AM
> To: dev@dpdk.org
> Cc: maxime.coquelin@redhat.com; stable@dpdk.org
> 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.
> 
> Coverity issue: 364233
> Fixes: ca059fa5e290 ("examples/vhost: demonstrate the new generic APIs")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Chenbo Xia <chenbo.xia@intel.com>
> ---
> 2.17.1

Applied to next-virtio/main, Thanks
diff mbox series

Patch

diff --git a/examples/vhost/virtio_net.c b/examples/vhost/virtio_net.c
index 64bf3d19ff..9064fc3a82 100644
--- a/examples/vhost/virtio_net.c
+++ b/examples/vhost/virtio_net.c
@@ -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++) {