]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
dmaengine: sh: rz-dmac: Use list_first_entry_or_null()
authorClaudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
Tue, 26 May 2026 08:46:55 +0000 (11:46 +0300)
committerVinod Koul <vkoul@kernel.org>
Thu, 4 Jun 2026 15:28:31 +0000 (20:58 +0530)
Use list_first_entry_or_null() instead of open-coding it with a
list_empty() check and list_first_entry(). This simplifies the code.

Reviewed-by: Frank Li <Frank.Li@nxp.com>
Tested-by: John Madieu <john.madieu.xa@bp.renesas.com>
Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
Tested-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
Link: https://patch.msgid.link/20260526084710.3491480-4-claudiu.beznea@kernel.org
Signed-off-by: Vinod Koul <vkoul@kernel.org>
drivers/dma/sh/rz-dmac.c

index 6d80cb668957fb5334bf2d5104e9a321fdcf32fd..1717b407ab9e97bbcafdd77b1bcfc9717601a3ea 100644 (file)
@@ -503,11 +503,10 @@ rz_dmac_prep_dma_memcpy(struct dma_chan *chan, dma_addr_t dest, dma_addr_t src,
                __func__, channel->index, &src, &dest, len);
 
        scoped_guard(spinlock_irqsave, &channel->vc.lock) {
-               if (list_empty(&channel->ld_free))
+               desc = list_first_entry_or_null(&channel->ld_free, struct rz_dmac_desc, node);
+               if (!desc)
                        return NULL;
 
-               desc = list_first_entry(&channel->ld_free, struct rz_dmac_desc, node);
-
                desc->type = RZ_DMAC_DESC_MEMCPY;
                desc->src = src;
                desc->dest = dest;
@@ -533,11 +532,10 @@ rz_dmac_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl,
        int i = 0;
 
        scoped_guard(spinlock_irqsave, &channel->vc.lock) {
-               if (list_empty(&channel->ld_free))
+               desc = list_first_entry_or_null(&channel->ld_free, struct rz_dmac_desc, node);
+               if (!desc)
                        return NULL;
 
-               desc = list_first_entry(&channel->ld_free, struct rz_dmac_desc, node);
-
                for_each_sg(sgl, sg, sg_len, i)
                        dma_length += sg_dma_len(sg);