dmaengine: dw-axi-dmac: simplify allocation
Subsystems (2)
PATCH 1/1 dmaengine: dw-axi-dmac: simplify allocation
Use a flexible array member with kzalloc_flex to combine allocations.
Add __counted_by for extra runtime analysis.
Signed-off-by Rosen Penev <[email protected]>
--- 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(-)
drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c +1 -7
@@ -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",
drivers/dma/dw-axi-dmac/dw-axi-dmac.h +2 -2
@@ -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 {
Signature · 1 line
2.53.0
Quoted 6 lines · Rosen Penev
Use a flexible array member with
kzalloc_flexto combine allocations.Add
__counted_byfor extra runtime analysis.Signed-off-by Rosen Penev <[email protected]>---
Reviewed-by Frank Li <[email protected]>
Quoted 57 lines
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(-)drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c +1
-7@@ -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",drivers/dma/dw-axi-dmac/dw-axi-dmac.h +2
-3@@ -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
On Mon, Mar 30, 2026 at 02:11:28PM -0700, Rosen Penev wrote:
Subject should
"use kzalloc_flex() to simplify allocation"
Quoted 1 line
Use a flexible array member with
kzalloc_flexto combine allocations.
function name need add (), kzalloc_flex()
Frank
Quoted 62 lines
Add
__counted_byfor extra runtime analysis.Signed-off-by Rosen Penev <[email protected]>--- 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(-)drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c +1
-7@@ -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",drivers/dma/dw-axi-dmac/dw-axi-dmac.h +2
-3@@ -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