dmaengine: rcar-dmac: Check the done lists in rcar_dmac_chan_get_residue()
authorYoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Fri, 2 Feb 2018 10:05:15 +0000 (19:05 +0900)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 30 May 2018 05:52:36 +0000 (07:52 +0200)
commitb3b26307208e93182df45231ef94483902cca43a
treeed1190d757017dd3841da9d544abf5f9fe08ad72
parente41de468a6f4f25895242ada6d95240a3ce968d8
dmaengine: rcar-dmac: Check the done lists in rcar_dmac_chan_get_residue()

[ Upstream commit 3e081628d510b2ddbe493371d9c574d9275da17e ]

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 <dung.nguyen.aj@renesas.com>
Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Signed-off-by: Vinod Koul <vinod.koul@intel.com>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/dma/sh/rcar-dmac.c