* [PATCH] dmaengine: dw-axi-dmac: simplify allocation
@ 2026-03-30 21:11 Rosen Penev
2026-04-06 10:08 ` Frank Li
2026-04-06 10:11 ` Frank Li
0 siblings, 2 replies; 3+ messages in thread
From: Rosen Penev @ 2026-03-30 21:11 UTC (permalink / raw)
To: dmaengine
Cc: Eugeniy Paltsev, Vinod Koul, Frank Li, Kees Cook,
Gustavo A. R. Silva, open list,
open list:KERNEL HARDENING (not covered by other areas):Keyword:b__counted_by(_le|_be)?b
Use a flexible array member with kzalloc_flex to combine allocations.
Add __counted_by for extra runtime analysis.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c | 8 +-------
drivers/dma/dw-axi-dmac/dw-axi-dmac.h | 4 ++--
2 files changed, 3 insertions(+), 9 deletions(-)
diff --git a/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c b/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c
index 4d53f077e9d2..d3ca202dc478 100644
--- a/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c
+++ b/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c
@@ -294,15 +294,10 @@ static struct axi_dma_desc *axi_desc_alloc(u32 num)
{
struct axi_dma_desc *desc;
- desc = kzalloc_obj(*desc, GFP_NOWAIT);
+ desc = kzalloc_flex(*desc, hw_desc, num, GFP_NOWAIT);
if (!desc)
return NULL;
- desc->hw_desc = kzalloc_objs(*desc->hw_desc, num, GFP_NOWAIT);
- if (!desc->hw_desc) {
- kfree(desc);
- return NULL;
- }
desc->nr_hw_descs = num;
return desc;
@@ -339,7 +334,6 @@ static void axi_desc_put(struct axi_dma_desc *desc)
dma_pool_free(chan->desc_pool, hw_desc->lli, hw_desc->llp);
}
- kfree(desc->hw_desc);
kfree(desc);
atomic_sub(descs_put, &chan->descs_allocated);
dev_vdbg(chan2dev(chan), "%s: %d descs put, %d still allocated\n",
diff --git a/drivers/dma/dw-axi-dmac/dw-axi-dmac.h b/drivers/dma/dw-axi-dmac/dw-axi-dmac.h
index 67cc199e24d1..a04a4e03eb3d 100644
--- a/drivers/dma/dw-axi-dmac/dw-axi-dmac.h
+++ b/drivers/dma/dw-axi-dmac/dw-axi-dmac.h
@@ -98,14 +98,14 @@ struct axi_dma_hw_desc {
};
struct axi_dma_desc {
- struct axi_dma_hw_desc *hw_desc;
-
struct virt_dma_desc vd;
struct axi_dma_chan *chan;
u32 completed_blocks;
u32 length;
u32 period_len;
u32 nr_hw_descs;
+
+ struct axi_dma_hw_desc hw_desc[] __counted_by(nr_hw_descs);
};
struct axi_dma_chan_config {
--
2.53.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] dmaengine: dw-axi-dmac: simplify allocation
2026-03-30 21:11 [PATCH] dmaengine: dw-axi-dmac: simplify allocation Rosen Penev
@ 2026-04-06 10:08 ` Frank Li
2026-04-06 10:11 ` Frank Li
1 sibling, 0 replies; 3+ messages in thread
From: Frank Li @ 2026-04-06 10:08 UTC (permalink / raw)
To: Rosen Penev
Cc: dmaengine, Eugeniy Paltsev, Vinod Koul, Frank Li, Kees Cook,
Gustavo A. R. Silva, open list,
open list:KERNEL HARDENING (not covered by other areas):Keyword:b__counted_by(_le|_be)?b
On Mon, Mar 30, 2026 at 02:11:28PM -0700, Rosen Penev wrote:
> Use a flexible array member with kzalloc_flex to combine allocations.
>
> Add __counted_by for extra runtime analysis.
>
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> ---
Reviewed-by: Frank Li <Frank.Li@nxp.com>
> drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c | 8 +-------
> drivers/dma/dw-axi-dmac/dw-axi-dmac.h | 4 ++--
> 2 files changed, 3 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c b/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c
> index 4d53f077e9d2..d3ca202dc478 100644
> --- a/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c
> +++ b/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c
> @@ -294,15 +294,10 @@ static struct axi_dma_desc *axi_desc_alloc(u32 num)
> {
> struct axi_dma_desc *desc;
>
> - desc = kzalloc_obj(*desc, GFP_NOWAIT);
> + desc = kzalloc_flex(*desc, hw_desc, num, GFP_NOWAIT);
> if (!desc)
> return NULL;
>
> - desc->hw_desc = kzalloc_objs(*desc->hw_desc, num, GFP_NOWAIT);
> - if (!desc->hw_desc) {
> - kfree(desc);
> - return NULL;
> - }
> desc->nr_hw_descs = num;
>
> return desc;
> @@ -339,7 +334,6 @@ static void axi_desc_put(struct axi_dma_desc *desc)
> dma_pool_free(chan->desc_pool, hw_desc->lli, hw_desc->llp);
> }
>
> - kfree(desc->hw_desc);
> kfree(desc);
> atomic_sub(descs_put, &chan->descs_allocated);
> dev_vdbg(chan2dev(chan), "%s: %d descs put, %d still allocated\n",
> diff --git a/drivers/dma/dw-axi-dmac/dw-axi-dmac.h b/drivers/dma/dw-axi-dmac/dw-axi-dmac.h
> index 67cc199e24d1..a04a4e03eb3d 100644
> --- a/drivers/dma/dw-axi-dmac/dw-axi-dmac.h
> +++ b/drivers/dma/dw-axi-dmac/dw-axi-dmac.h
> @@ -98,14 +98,14 @@ struct axi_dma_hw_desc {
> };
>
> struct axi_dma_desc {
> - struct axi_dma_hw_desc *hw_desc;
> -
> struct virt_dma_desc vd;
> struct axi_dma_chan *chan;
> u32 completed_blocks;
> u32 length;
> u32 period_len;
> u32 nr_hw_descs;
> +
> + struct axi_dma_hw_desc hw_desc[] __counted_by(nr_hw_descs);
> };
>
> struct axi_dma_chan_config {
> --
> 2.53.0
>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] dmaengine: dw-axi-dmac: simplify allocation
2026-03-30 21:11 [PATCH] dmaengine: dw-axi-dmac: simplify allocation Rosen Penev
2026-04-06 10:08 ` Frank Li
@ 2026-04-06 10:11 ` Frank Li
1 sibling, 0 replies; 3+ messages in thread
From: Frank Li @ 2026-04-06 10:11 UTC (permalink / raw)
To: Rosen Penev
Cc: dmaengine, Eugeniy Paltsev, Vinod Koul, Frank Li, Kees Cook,
Gustavo A. R. Silva, open list,
open list:KERNEL HARDENING (not covered by other areas):Keyword:b__counted_by(_le|_be)?b
On Mon, Mar 30, 2026 at 02:11:28PM -0700, Rosen Penev wrote:
Subject should
"use kzalloc_flex() to simplify allocation"
> Use a flexible array member with kzalloc_flex to combine allocations.
function name need add (), kzalloc_flex()
Frank
>
> Add __counted_by for extra runtime analysis.
>
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> ---
> drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c | 8 +-------
> drivers/dma/dw-axi-dmac/dw-axi-dmac.h | 4 ++--
> 2 files changed, 3 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c b/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c
> index 4d53f077e9d2..d3ca202dc478 100644
> --- a/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c
> +++ b/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c
> @@ -294,15 +294,10 @@ static struct axi_dma_desc *axi_desc_alloc(u32 num)
> {
> struct axi_dma_desc *desc;
>
> - desc = kzalloc_obj(*desc, GFP_NOWAIT);
> + desc = kzalloc_flex(*desc, hw_desc, num, GFP_NOWAIT);
> if (!desc)
> return NULL;
>
> - desc->hw_desc = kzalloc_objs(*desc->hw_desc, num, GFP_NOWAIT);
> - if (!desc->hw_desc) {
> - kfree(desc);
> - return NULL;
> - }
> desc->nr_hw_descs = num;
>
> return desc;
> @@ -339,7 +334,6 @@ static void axi_desc_put(struct axi_dma_desc *desc)
> dma_pool_free(chan->desc_pool, hw_desc->lli, hw_desc->llp);
> }
>
> - kfree(desc->hw_desc);
> kfree(desc);
> atomic_sub(descs_put, &chan->descs_allocated);
> dev_vdbg(chan2dev(chan), "%s: %d descs put, %d still allocated\n",
> diff --git a/drivers/dma/dw-axi-dmac/dw-axi-dmac.h b/drivers/dma/dw-axi-dmac/dw-axi-dmac.h
> index 67cc199e24d1..a04a4e03eb3d 100644
> --- a/drivers/dma/dw-axi-dmac/dw-axi-dmac.h
> +++ b/drivers/dma/dw-axi-dmac/dw-axi-dmac.h
> @@ -98,14 +98,14 @@ struct axi_dma_hw_desc {
> };
>
> struct axi_dma_desc {
> - struct axi_dma_hw_desc *hw_desc;
> -
> struct virt_dma_desc vd;
> struct axi_dma_chan *chan;
> u32 completed_blocks;
> u32 length;
> u32 period_len;
> u32 nr_hw_descs;
> +
> + struct axi_dma_hw_desc hw_desc[] __counted_by(nr_hw_descs);
> };
>
> struct axi_dma_chan_config {
> --
> 2.53.0
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-04-06 10:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-30 21:11 [PATCH] dmaengine: dw-axi-dmac: simplify allocation Rosen Penev
2026-04-06 10:08 ` Frank Li
2026-04-06 10:11 ` Frank Li
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox