Skip to contentSkip to conversation

dmaengine: sh: rz-dmac: Fix off-by-one in residue lmdesc lookup

PATCH Applied Claudiu Beznea 3 participants 3 messages Sep 22 – Oct 5

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dmaengine: sh: rz-dmac: Fix off-by-one in residue lmdesc lookup

From: Tommaso Merciai <[email protected]>

lmdesc->nxla is the address of the next descriptor, so comparing it against CRLA, which is the address of the current descriptor, finds the descriptor before the active one, not the active one. The residue loops below then summed one lmdesc too many on top of that.

Compare each descriptor's own address to CRLA instead, and add tb after advancing to the next lmdesc.

Fixes 21323b118c16 ("dmaengine: sh: rz-dmac: Add device_tx_status() callback")
Fixes 172bfb57481c ("dmaengine: sh: rz-dmac: Add cyclic DMA support")
---
 drivers/dma/sh/rz-dmac.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/dma/sh/rz-dmac.c +3 -3
index ca76f1bb45c4..fdd7131e890a 100644
@@ -937,7 +937,7 @@ static u32 rz_dmac_calculate_residue_bytes_in_vd(struct rz_dmac_chan *channel,
 	struct rz_dmac *dmac = to_rz_dmac(chan->device);
 	u32 residue = 0, i = 0;
 
-	while (lmdesc->nxla != crla) {
+	while (rz_dmac_lmdesc_addr(channel, lmdesc) != crla) {
 		lmdesc = rz_dmac_get_next_lmdesc(channel->lmdesc.base, lmdesc);
 		if (++i >= DMAC_NR_LMDESC)
 			return 0;
@@ -948,13 +948,13 @@ static u32 rz_dmac_calculate_residue_bytes_in_vd(struct rz_dmac_chan *channel,
 		u32 start_lmdesc_addr = rz_dmac_lmdesc_addr(channel, desc->start_lmdesc);
 
 		while (lmdesc->nxla != start_lmdesc_addr) {
-			residue += lmdesc->tb;
 			lmdesc = rz_dmac_get_next_lmdesc(channel->lmdesc.base, lmdesc);
+			residue += lmdesc->tb;
 		}
 	} else {
 		while (lmdesc->chcfg & CHCFG_DEM) {
-			residue += lmdesc->tb;
 			lmdesc = rz_dmac_get_next_lmdesc(channel->lmdesc.base, lmdesc);
+			residue += lmdesc->tb;
 		}
 	}
 
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Claudiu Beznea

From: Tommaso Merciai <[email protected]>

lmdesc->nxla is the address of the next descriptor, so comparing it against CRLA, which is the address of the current descriptor, finds the descriptor before the active one, not the active one. The residue loops below then summed one lmdesc too many on top of that.

Compare each descriptor's own address to CRLA instead, and add tb after advancing to the next lmdesc.

Quoted 7 lines
Fixes 21323b118c16 ("dmaengine: sh: rz-dmac: Add device_tx_status() callback")
Fixes 172bfb57481c ("dmaengine: sh: rz-dmac: Add cyclic DMA support")

---

Quoted 35 lines
 drivers/dma/sh/rz-dmac.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/dma/sh/rz-dmac.c +3 -4
index ca76f1bb45c4..fdd7131e890a 100644
@@ -937,7 +937,7 @@ static u32 rz_dmac_calculate_residue_bytes_in_vd(struct rz_dmac_chan *channel,
 	struct rz_dmac *dmac = to_rz_dmac(chan->device);
 	u32 residue = 0, i = 0;
 
-	while (lmdesc->nxla != crla) {
+	while (rz_dmac_lmdesc_addr(channel, lmdesc) != crla) {
 		lmdesc = rz_dmac_get_next_lmdesc(channel->lmdesc.base, lmdesc);
 		if (++i >= DMAC_NR_LMDESC)
 			return 0;
@@ -948,13 +948,13 @@ static u32 rz_dmac_calculate_residue_bytes_in_vd(struct rz_dmac_chan *channel,
 		u32 start_lmdesc_addr = rz_dmac_lmdesc_addr(channel, desc->start_lmdesc);
 
 		while (lmdesc->nxla != start_lmdesc_addr) {
-			residue += lmdesc->tb;
 			lmdesc = rz_dmac_get_next_lmdesc(channel->lmdesc.base, lmdesc);
+			residue += lmdesc->tb;
 		}
 	} else {
 		while (lmdesc->chcfg & CHCFG_DEM) {
-			residue += lmdesc->tb;
 			lmdesc = rz_dmac_get_next_lmdesc(channel->lmdesc.base, lmdesc);
+			residue += lmdesc->tb;
 		}
 	}
 
--

2.43.0

maintainer Applied
#2 lore raw
In reply to Claudiu Beznea
Quoted 10 lines · Claudiu Beznea

lmdesc->nxla is the address of the next descriptor, so comparing it against CRLA, which is the address of the current descriptor, finds the descriptor before the active one, not the active one. The residue loops below then summed one lmdesc too many on top of that.

Compare each descriptor's own address to CRLA instead, and add tb after advancing to the next lmdesc.

[...]

Applied, thanks!

[1/1] dmaengine: sh: rz-dmac: Fix off-by-one in residue lmdesc lookup

      commit: 9db8e502b34bc1df8078abd0169a4fa0624de3bb

Best regards,

Signature · 1 line
~Vinod