net/virtio-user: check value returned from malloc
authorJianfeng Tan <jianfeng.tan@intel.com>
Thu, 26 Jan 2017 03:05:42 +0000 (03:05 +0000)
committerYuanhan Liu <yuanhan.liu@linux.intel.com>
Sat, 28 Jan 2017 13:25:40 +0000 (14:25 +0100)
commit1e9057a97b3d5045f17412f19a9dc578a8067cc9
treef8cf7b23b0c6e1c99b41c8f47e3bf46d2927a2fd
parent7687312571c90c3e5f93a4eb29c7a45c828d1f79
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 <jianfeng.tan@intel.com>
Acked-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
drivers/net/virtio/virtio_user/vhost_kernel.c