Currently when the allocation of gntdev_dmabuf fails, the error exit
path will call dmabuf_imp_free_storage and causes a null pointer
dereference on gntdev_dmabuf. Fix this by adding an error exit path
that won't free gntdev_dmabuf.
Detected by CoverityScan, CID#
1472124 ("Dereference after null check")
Fixes: bf8dc55b1358 ("xen/gntdev: Implement dma-buf import functionality")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Signed-off-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
gntdev_dmabuf = kzalloc(sizeof(*gntdev_dmabuf), GFP_KERNEL);
if (!gntdev_dmabuf)
- goto fail;
+ goto fail_no_free;
gntdev_dmabuf->u.imp.refs = kcalloc(count,
sizeof(gntdev_dmabuf->u.imp.refs[0]),
fail:
dmabuf_imp_free_storage(gntdev_dmabuf);
+fail_no_free:
return ERR_PTR(-ENOMEM);
}