mirror of
https://github.com/torvalds/linux.git
synced 2026-05-29 17:43:52 +02:00
accel/amdxdna: Fix memory leak in amdxdna_ubuf_map
The amdxdna_ubuf_map() function allocates memory for sg and
internal sg table structures, but it fails to free them if subsequent
operations (sg_alloc_table_from_pages or dma_map_sgtable) fail.
Fixes: bd72d4acda ("accel/amdxdna: Support user space allocated buffer")
Signed-off-by: Zishun Yi <zishun.yi.dev@gmail.com>
Reviewed-by: Lizhi Hou <lizhi.hou@amd.com>
Reviewed-by: Min Ma <mamin506@gmail.com>
Signed-off-by: Lizhi Hou <lizhi.hou@amd.com>
Link: https://patch.msgid.link/20260129171022.68578-1-zishun.yi.dev@gmail.com
This commit is contained in:
parent
f1370241fe
commit
84dd57fb03
|
|
@ -34,15 +34,21 @@ static struct sg_table *amdxdna_ubuf_map(struct dma_buf_attachment *attach,
|
|||
ret = sg_alloc_table_from_pages(sg, ubuf->pages, ubuf->nr_pages, 0,
|
||||
ubuf->nr_pages << PAGE_SHIFT, GFP_KERNEL);
|
||||
if (ret)
|
||||
return ERR_PTR(ret);
|
||||
goto err_free_sg;
|
||||
|
||||
if (ubuf->flags & AMDXDNA_UBUF_FLAG_MAP_DMA) {
|
||||
ret = dma_map_sgtable(attach->dev, sg, direction, 0);
|
||||
if (ret)
|
||||
return ERR_PTR(ret);
|
||||
goto err_free_table;
|
||||
}
|
||||
|
||||
return sg;
|
||||
|
||||
err_free_table:
|
||||
sg_free_table(sg);
|
||||
err_free_sg:
|
||||
kfree(sg);
|
||||
return ERR_PTR(ret);
|
||||
}
|
||||
|
||||
static void amdxdna_ubuf_unmap(struct dma_buf_attachment *attach,
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user