public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH] dmaengine: milbeaut-hdmac: use kzalloc_flex
@ 2026-03-08 22:21 Rosen Penev
  0 siblings, 0 replies; only message in thread
From: Rosen Penev @ 2026-03-08 22:21 UTC (permalink / raw)
  To: dmaengine
  Cc: Vinod Koul, Frank Li, Taichi Sugaya, Takao Orito, Kees Cook,
	Gustavo A. R. Silva, moderated list:ARM/MILBEAUT ARCHITECTURE,
	open list,
	open list:KERNEL HARDENING (not covered by other areas):Keyword:b__counted_by(_le|_be)?b

Reduces allocation to a single one for simplicity.

Added __counted_by for extra runtime analysis.

Replace loop with memcpy. The loop adds no value here.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 drivers/dma/milbeaut-hdmac.c | 16 +++-------------
 1 file changed, 3 insertions(+), 13 deletions(-)

diff --git a/drivers/dma/milbeaut-hdmac.c b/drivers/dma/milbeaut-hdmac.c
index b4ebc09e80d0..2e15a2256b55 100644
--- a/drivers/dma/milbeaut-hdmac.c
+++ b/drivers/dma/milbeaut-hdmac.c
@@ -58,10 +58,10 @@
 
 struct milbeaut_hdmac_desc {
 	struct virt_dma_desc vd;
-	struct scatterlist *sgl;
 	unsigned int sg_len;
 	unsigned int sg_cur;
 	enum dma_transfer_direction dir;
+	struct scatterlist sgl[] __counted_by(sg_len);
 };
 
 struct milbeaut_hdmac_chan {
@@ -260,25 +260,16 @@ milbeaut_hdmac_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl,
 {
 	struct virt_dma_chan *vc = to_virt_chan(chan);
 	struct milbeaut_hdmac_desc *md;
-	int i;
 
 	if (!is_slave_direction(direction))
 		return NULL;
 
-	md = kzalloc_obj(*md, GFP_NOWAIT);
+	md = kzalloc_flex(*md, sgl, sg_len, GFP_NOWAIT);
 	if (!md)
 		return NULL;
 
-	md->sgl = kzalloc_objs(*sgl, sg_len, GFP_NOWAIT);
-	if (!md->sgl) {
-		kfree(md);
-		return NULL;
-	}
-
-	for (i = 0; i < sg_len; i++)
-		md->sgl[i] = sgl[i];
-
 	md->sg_len = sg_len;
+	memcpy(md->sgl, sgl, sg_len * sizeof(*sgl));
 	md->dir = direction;
 
 	return vchan_tx_prep(vc, &md->vd, flags);
@@ -395,7 +386,6 @@ static void milbeaut_hdmac_desc_free(struct virt_dma_desc *vd)
 {
 	struct milbeaut_hdmac_desc *md = to_milbeaut_hdmac_desc(vd);
 
-	kfree(md->sgl);
 	kfree(md);
 }
 
-- 
2.53.0



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-03-08 22:22 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-08 22:21 [PATCH] dmaengine: milbeaut-hdmac: use kzalloc_flex Rosen Penev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox