Skip to content

Commit 3e08162

Browse files
shimodayVinod Koul
authored andcommitted
dmaengine: rcar-dmac: Check the done lists in rcar_dmac_chan_get_residue()
This patch fixes an issue that a race condition happens between a client driver and the rcar-dmac driver: - The rcar_dmac_isr_transfer_end() is called. - The done list appears, and desc.running is the next active list. - rcar_dmac_chan_get_residue() is called by a client driver before rcar_dmac_isr_channel_thread() is called. - The rcar_dmac_chan_get_residue() will not find any descriptors. - And, the following WARNING happens: WARN(1, "No descriptor for cookie!"); The sh-sci driver with HSCIF (921,600bps) on R-Car H3 can cause this situation. So, this patch checks the done lists in rcar_dmac_chan_get_residue() and returns zero if the done lists has the argument cookie. Tested-by: Nguyen Viet Dung <[email protected]> Signed-off-by: Yoshihiro Shimoda <[email protected]> Signed-off-by: Vinod Koul <[email protected]>
1 parent db1de9d commit 3e08162

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

drivers/dma/sh/rcar-dmac.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,8 +1301,17 @@ static unsigned int rcar_dmac_chan_get_residue(struct rcar_dmac_chan *chan,
13011301
* If the cookie doesn't correspond to the currently running transfer
13021302
* then the descriptor hasn't been processed yet, and the residue is
13031303
* equal to the full descriptor size.
1304+
* Also, a client driver is possible to call this function before
1305+
* rcar_dmac_isr_channel_thread() runs. In this case, the "desc.running"
1306+
* will be the next descriptor, and the done list will appear. So, if
1307+
* the argument cookie matches the done list's cookie, we can assume
1308+
* the residue is zero.
13041309
*/
13051310
if (cookie != desc->async_tx.cookie) {
1311+
list_for_each_entry(desc, &chan->desc.done, node) {
1312+
if (cookie == desc->async_tx.cookie)
1313+
return 0;
1314+
}
13061315
list_for_each_entry(desc, &chan->desc.pending, node) {
13071316
if (cookie == desc->async_tx.cookie)
13081317
return desc->size;

0 commit comments

Comments
 (0)