Skip to content

Commit 84dd57f

Browse files
yizishunhoulz0507
authored andcommitted
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: bd72d4a ("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
1 parent f137024 commit 84dd57f

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

drivers/accel/amdxdna/amdxdna_ubuf.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,21 @@ static struct sg_table *amdxdna_ubuf_map(struct dma_buf_attachment *attach,
3434
ret = sg_alloc_table_from_pages(sg, ubuf->pages, ubuf->nr_pages, 0,
3535
ubuf->nr_pages << PAGE_SHIFT, GFP_KERNEL);
3636
if (ret)
37-
return ERR_PTR(ret);
37+
goto err_free_sg;
3838

3939
if (ubuf->flags & AMDXDNA_UBUF_FLAG_MAP_DMA) {
4040
ret = dma_map_sgtable(attach->dev, sg, direction, 0);
4141
if (ret)
42-
return ERR_PTR(ret);
42+
goto err_free_table;
4343
}
4444

4545
return sg;
46+
47+
err_free_table:
48+
sg_free_table(sg);
49+
err_free_sg:
50+
kfree(sg);
51+
return ERR_PTR(ret);
4652
}
4753

4854
static void amdxdna_ubuf_unmap(struct dma_buf_attachment *attach,

0 commit comments

Comments
 (0)