Commit 2789e83c authored by Colin Ian King's avatar Colin Ian King Committed by Boris Ostrovsky

xen/gntdev: don't dereference a null gntdev_dmabuf on allocation failure

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: bf8dc55b ("xen/gntdev: Implement dma-buf import functionality")
Signed-off-by: default avatarColin Ian King <colin.king@canonical.com>
Reviewed-by: default avatarBoris Ostrovsky <boris.ostrovsky@oracle.com>
Signed-off-by: default avatarBoris Ostrovsky <boris.ostrovsky@oracle.com>
parent 47b428d1
...@@ -569,7 +569,7 @@ static struct gntdev_dmabuf *dmabuf_imp_alloc_storage(int count) ...@@ -569,7 +569,7 @@ static struct gntdev_dmabuf *dmabuf_imp_alloc_storage(int count)
gntdev_dmabuf = kzalloc(sizeof(*gntdev_dmabuf), GFP_KERNEL); gntdev_dmabuf = kzalloc(sizeof(*gntdev_dmabuf), GFP_KERNEL);
if (!gntdev_dmabuf) if (!gntdev_dmabuf)
goto fail; goto fail_no_free;
gntdev_dmabuf->u.imp.refs = kcalloc(count, gntdev_dmabuf->u.imp.refs = kcalloc(count,
sizeof(gntdev_dmabuf->u.imp.refs[0]), sizeof(gntdev_dmabuf->u.imp.refs[0]),
...@@ -592,6 +592,7 @@ static struct gntdev_dmabuf *dmabuf_imp_alloc_storage(int count) ...@@ -592,6 +592,7 @@ static struct gntdev_dmabuf *dmabuf_imp_alloc_storage(int count)
fail: fail:
dmabuf_imp_free_storage(gntdev_dmabuf); dmabuf_imp_free_storage(gntdev_dmabuf);
fail_no_free:
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment