udmabuf: improve map_udmabuf error handling

Reported-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/20180911134216.9760-3-kraxel@redhat.com
This commit is contained in:
Gerd Hoffmann 2018-09-11 15:42:05 +02:00
parent 913965c42c
commit a3e722dad0
1 changed files with 10 additions and 11 deletions

View File

@ -51,25 +51,24 @@ static struct sg_table *map_udmabuf(struct dma_buf_attachment *at,
{ {
struct udmabuf *ubuf = at->dmabuf->priv; struct udmabuf *ubuf = at->dmabuf->priv;
struct sg_table *sg; struct sg_table *sg;
int ret;
sg = kzalloc(sizeof(*sg), GFP_KERNEL); sg = kzalloc(sizeof(*sg), GFP_KERNEL);
if (!sg) if (!sg)
goto err1; return ERR_PTR(-ENOMEM);
if (sg_alloc_table_from_pages(sg, ubuf->pages, ubuf->pagecount, ret = sg_alloc_table_from_pages(sg, ubuf->pages, ubuf->pagecount,
0, ubuf->pagecount << PAGE_SHIFT, 0, ubuf->pagecount << PAGE_SHIFT,
GFP_KERNEL) < 0) GFP_KERNEL);
goto err2; if (ret < 0)
goto err;
if (!dma_map_sg(at->dev, sg->sgl, sg->nents, direction)) if (!dma_map_sg(at->dev, sg->sgl, sg->nents, direction))
goto err3; goto err;
return sg; return sg;
err3: err:
sg_free_table(sg); sg_free_table(sg);
err2:
kfree(sg); kfree(sg);
err1: return ERR_PTR(ret);
return ERR_PTR(-ENOMEM);
} }
static void unmap_udmabuf(struct dma_buf_attachment *at, static void unmap_udmabuf(struct dma_buf_attachment *at,