* [PATCH v2] accel/amdxdna: Fix memory leak in amdxdna_ubuf_map
@ 2026-01-29 17:10 zishun yi
2026-01-29 17:23 ` Lizhi Hou
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: zishun yi @ 2026-01-29 17:10 UTC (permalink / raw)
To: Min Ma, Lizhi Hou, Oded Gabbay; +Cc: dri-devel, linux-kernel, Zishun Yi
From: Zishun Yi <zishun.yi.dev@gmail.com>
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: bd72d4acda10 ("accel/amdxdna: Support user space allocated buffer")
Signed-off-by: Zishun Yi <zishun.yi.dev@gmail.com>
---
v2: Add 'Fixes' tag
drivers/accel/amdxdna/amdxdna_ubuf.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/drivers/accel/amdxdna/amdxdna_ubuf.c b/drivers/accel/amdxdna/amdxdna_ubuf.c
index 077b2261cf2a..9e3b3b055caa 100644
--- a/drivers/accel/amdxdna/amdxdna_ubuf.c
+++ b/drivers/accel/amdxdna/amdxdna_ubuf.c
@@ -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,
--
2.51.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] accel/amdxdna: Fix memory leak in amdxdna_ubuf_map
2026-01-29 17:10 [PATCH v2] accel/amdxdna: Fix memory leak in amdxdna_ubuf_map zishun yi
@ 2026-01-29 17:23 ` Lizhi Hou
2026-01-30 7:35 ` Min Ma
2026-01-30 21:09 ` Lizhi Hou
2 siblings, 0 replies; 4+ messages in thread
From: Lizhi Hou @ 2026-01-29 17:23 UTC (permalink / raw)
To: zishun yi, Min Ma, Oded Gabbay; +Cc: dri-devel, linux-kernel
Reviewed-by: Lizhi Hou <lizhi.hou@amd.com>
On 1/29/26 09:10, zishun yi wrote:
> From: Zishun Yi <zishun.yi.dev@gmail.com>
>
> 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: bd72d4acda10 ("accel/amdxdna: Support user space allocated buffer")
> Signed-off-by: Zishun Yi <zishun.yi.dev@gmail.com>
> ---
> v2: Add 'Fixes' tag
>
> drivers/accel/amdxdna/amdxdna_ubuf.c | 10 ++++++++--
> 1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/accel/amdxdna/amdxdna_ubuf.c b/drivers/accel/amdxdna/amdxdna_ubuf.c
> index 077b2261cf2a..9e3b3b055caa 100644
> --- a/drivers/accel/amdxdna/amdxdna_ubuf.c
> +++ b/drivers/accel/amdxdna/amdxdna_ubuf.c
> @@ -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,
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] accel/amdxdna: Fix memory leak in amdxdna_ubuf_map
2026-01-29 17:10 [PATCH v2] accel/amdxdna: Fix memory leak in amdxdna_ubuf_map zishun yi
2026-01-29 17:23 ` Lizhi Hou
@ 2026-01-30 7:35 ` Min Ma
2026-01-30 21:09 ` Lizhi Hou
2 siblings, 0 replies; 4+ messages in thread
From: Min Ma @ 2026-01-30 7:35 UTC (permalink / raw)
To: zishun.yi.dev; +Cc: dri-devel, linux-kernel, lizhi.hou, mamin506, ogabbay
Looks good.
Reviewed-by: Min Ma <mamin506@gmail.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] accel/amdxdna: Fix memory leak in amdxdna_ubuf_map
2026-01-29 17:10 [PATCH v2] accel/amdxdna: Fix memory leak in amdxdna_ubuf_map zishun yi
2026-01-29 17:23 ` Lizhi Hou
2026-01-30 7:35 ` Min Ma
@ 2026-01-30 21:09 ` Lizhi Hou
2 siblings, 0 replies; 4+ messages in thread
From: Lizhi Hou @ 2026-01-30 21:09 UTC (permalink / raw)
To: zishun yi, Min Ma, Oded Gabbay; +Cc: dri-devel, linux-kernel
Applied to drm-misc-next-fixes.
On 1/29/26 09:10, zishun yi wrote:
> From: Zishun Yi <zishun.yi.dev@gmail.com>
>
> 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: bd72d4acda10 ("accel/amdxdna: Support user space allocated buffer")
> Signed-off-by: Zishun Yi <zishun.yi.dev@gmail.com>
> ---
> v2: Add 'Fixes' tag
>
> drivers/accel/amdxdna/amdxdna_ubuf.c | 10 ++++++++--
> 1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/accel/amdxdna/amdxdna_ubuf.c b/drivers/accel/amdxdna/amdxdna_ubuf.c
> index 077b2261cf2a..9e3b3b055caa 100644
> --- a/drivers/accel/amdxdna/amdxdna_ubuf.c
> +++ b/drivers/accel/amdxdna/amdxdna_ubuf.c
> @@ -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,
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-01-30 21:09 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-29 17:10 [PATCH v2] accel/amdxdna: Fix memory leak in amdxdna_ubuf_map zishun yi
2026-01-29 17:23 ` Lizhi Hou
2026-01-30 7:35 ` Min Ma
2026-01-30 21:09 ` Lizhi Hou
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®