Commit abb863e6 authored by Claudiu Beznea's avatar Claudiu Beznea Committed by Vinod Koul
Browse files

dmaengine: sh: rz-dmac: Protect the driver specific lists



The driver lists (ld_free, ld_queue) are used in
rz_dmac_free_chan_resources(), rz_dmac_terminate_all(),
rz_dmac_issue_pending(), and rz_dmac_irq_handler_thread(), all under
the virtual channel lock. Take the same lock in rz_dmac_prep_slave_sg()
and rz_dmac_prep_dma_memcpy() as well to avoid concurrency issues, since
these functions also check whether the lists are empty and update or
remove list entries.

Fixes: 5000d370 ("dmaengine: sh: Add DMAC driver for RZ/G2L SoC")
Cc: stable@vger.kernel.org
Reviewed-by: default avatarFrank Li <Frank.Li@nxp.com>
Signed-off-by: default avatarClaudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
Link: https://patch.msgid.link/20260316133252.240348-2-claudiu.beznea.uj@bp.renesas.com


Signed-off-by: default avatarVinod Koul <vkoul@kernel.org>
parent e1c98661
Loading
Loading
Loading
Loading
+32 −25
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@
 */

#include <linux/bitfield.h>
#include <linux/cleanup.h>
#include <linux/dma-mapping.h>
#include <linux/dmaengine.h>
#include <linux/interrupt.h>
@@ -447,6 +448,7 @@ static int rz_dmac_alloc_chan_resources(struct dma_chan *chan)
		if (!desc)
			break;

		/* No need to lock. This is called only for the 1st client. */
		list_add_tail(&desc->node, &channel->ld_free);
		channel->descs_allocated++;
	}
@@ -502,6 +504,7 @@ rz_dmac_prep_dma_memcpy(struct dma_chan *chan, dma_addr_t dest, dma_addr_t src,
	dev_dbg(dmac->dev, "%s channel: %d src=0x%pad dst=0x%pad len=%zu\n",
		__func__, channel->index, &src, &dest, len);

	scoped_guard(spinlock_irqsave, &channel->vc.lock) {
		if (list_empty(&channel->ld_free))
			return NULL;

@@ -514,6 +517,8 @@ rz_dmac_prep_dma_memcpy(struct dma_chan *chan, dma_addr_t dest, dma_addr_t src,
		desc->direction = DMA_MEM_TO_MEM;

		list_move_tail(channel->ld_free.next, &channel->ld_queue);
	}

	return vchan_tx_prep(&channel->vc, &desc->vd, flags);
}

@@ -529,14 +534,14 @@ rz_dmac_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl,
	int dma_length = 0;
	int i = 0;

	scoped_guard(spinlock_irqsave, &channel->vc.lock) {
		if (list_empty(&channel->ld_free))
			return NULL;

		desc = list_first_entry(&channel->ld_free, struct rz_dmac_desc, node);

	for_each_sg(sgl, sg, sg_len, i) {
		for_each_sg(sgl, sg, sg_len, i)
			dma_length += sg_dma_len(sg);
	}

		desc->type = RZ_DMAC_DESC_SLAVE_SG;
		desc->sg = sgl;
@@ -550,6 +555,8 @@ rz_dmac_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl,
			desc->dest = channel->dst_per_address;

		list_move_tail(channel->ld_free.next, &channel->ld_queue);
	}

	return vchan_tx_prep(&channel->vc, &desc->vd, flags);
}