From: Jianfeng Tan Date: Thu, 26 Jan 2017 03:05:42 +0000 (+0000) Subject: net/virtio-user: check value returned from malloc X-Git-Tag: spdx-start~4635 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=1e9057a97b3d5045f17412f19a9dc578a8067cc9;p=dpdk.git net/virtio-user: check value returned from malloc Value returned from malloc is not checked for errors before being used. This patch fixes following coverity issue. static struct vhost_memory_kernel * prepare_vhost_memory_kernel(void) { ... vm = malloc(sizeof(struct vhost_memory_kernel) + max_regions * sizeof(struct vhost_memory_region)); ... >>> CID 140744: (NULL_RETURNS) >>> Dereferencing a null pointer "vm". mr = &vm->regions[k++]; Coverity issue: 140744 Fixes: e3b434818bbb ("net/virtio-user: support kernel vhost") Signed-off-by: Jianfeng Tan Acked-by: Yuanhan Liu --- diff --git a/drivers/net/virtio/virtio_user/vhost_kernel.c b/drivers/net/virtio/virtio_user/vhost_kernel.c index 9b6637d6a2..05aa6c6d5c 100644 --- a/drivers/net/virtio/virtio_user/vhost_kernel.c +++ b/drivers/net/virtio/virtio_user/vhost_kernel.c @@ -114,6 +114,8 @@ prepare_vhost_memory_kernel(void) vm = malloc(sizeof(struct vhost_memory_kernel) + max_regions * sizeof(struct vhost_memory_region)); + if (!vm) + return NULL; for (i = 0; i < RTE_MAX_MEMSEG; ++i) { seg = &rte_eal_get_configuration()->mem_config->memseg[i];