dmaengine.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] dmaengine: rcar-dmac: Reject zero-length slave DMA requests
@ 2019-06-24 12:38 Geert Uytterhoeven
  2019-06-24 12:49 ` Wolfram Sang
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Geert Uytterhoeven @ 2019-06-24 12:38 UTC (permalink / raw)
  To: Vinod Koul, Dan Williams, Eugeniu Rosca
  Cc: Greg Kroah-Hartman, Jiri Slaby, Yoshihiro Shimoda, Wolfram Sang,
	linux-serial, linux-renesas-soc, dmaengine, Geert Uytterhoeven

While the .device_prep_slave_sg() callback rejects empty scatterlists,
it still accepts single-entry scatterlists with a zero-length segment.
These may happen if a driver calls dmaengine_prep_slave_single() with a
zero len parameter.  The corresponding DMA request will never complete,
leading to messages like:

    rcar-dmac e7300000.dma-controller: Channel Address Error happen

and DMA timeouts.

Although requesting a zero-length DMA request is a driver bug, rejecting
it early eases debugging.  Note that the .device_prep_dma_memcpy()
callback already rejects requests to copy zero bytes.

Reported-by: Eugeniu Rosca <erosca@de.adit-jv.com>
Analyzed-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
See "[PATCH 0/2] serial: sh-sci: Fix .flush_buffer() issues"
(https://lore.kernel.org/linux-renesas-soc/20190624123540.20629-1-geert+renesas@glider.be/)
for the driver fix.

 drivers/dma/sh/rcar-dmac.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/dma/sh/rcar-dmac.c b/drivers/dma/sh/rcar-dmac.c
index 67df54ac329400b7..9c41a4e425759fcc 100644
--- a/drivers/dma/sh/rcar-dmac.c
+++ b/drivers/dma/sh/rcar-dmac.c
@@ -1165,7 +1165,7 @@ rcar_dmac_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl,
 	struct rcar_dmac_chan *rchan = to_rcar_dmac_chan(chan);
 
 	/* Someone calling slave DMA on a generic channel? */
-	if (rchan->mid_rid < 0 || !sg_len) {
+	if (rchan->mid_rid < 0 || !sg_len || !sg_dma_len(sgl)) {
 		dev_warn(chan->device->dev,
 			 "%s: bad parameter: len=%d, id=%d\n",
 			 __func__, sg_len, rchan->mid_rid);
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2019-07-03 15:34 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-24 12:38 [PATCH] dmaengine: rcar-dmac: Reject zero-length slave DMA requests Geert Uytterhoeven
2019-06-24 12:49 ` Wolfram Sang
2019-06-25  4:38 ` Vinod Koul
2019-06-25  4:40 ` Vinod Koul
2019-06-26 18:14 ` Eugeniu Rosca
2019-06-28 12:10   ` Geert Uytterhoeven
2019-06-28 12:57     ` Wolfram Sang
2019-07-03 15:34     ` Eugeniu Rosca

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).