Re: [PATCH v6 13/18] dmaengine: sh: rz-dmac: Adjust rz_dmac_chan_get_residue() to return error codes
From: Tommaso Merciai
Date: Thu May 28 2026 - 09:55:32 EST
On Tue, May 26, 2026 at 11:47:05AM +0300, Claudiu Beznea wrote:
> From: Claudiu Beznea <claudiu.beznea.uj@xxxxxxxxxxxxxx>
>
> Adjust rz_dmac_chan_get_residue() to return error codes on failure and
> provide the residue to callers through the residue parameter. This
> prepares the code for the addition of runtime PM support.
>
Tested-by: Tommaso Merciai <tommaso.merciai.xr@xxxxxxxxxxxxxx>
> Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@xxxxxxxxxxxxxx>
> ---
>
> Changes in v6:
> - none, this patch is new
>
> drivers/dma/sh/rz-dmac.c | 19 ++++++++++++++-----
> 1 file changed, 14 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c
> index 8fd8a4bd9cc9..93394b9934c8 100644
> --- a/drivers/dma/sh/rz-dmac.c
> +++ b/drivers/dma/sh/rz-dmac.c
> @@ -860,8 +860,8 @@ static u32 rz_dmac_calculate_residue_bytes_in_vd(struct rz_dmac_chan *channel,
> return residue;
> }
>
> -static u32 rz_dmac_chan_get_residue(struct rz_dmac_chan *channel,
> - dma_cookie_t cookie)
> +static int rz_dmac_chan_get_residue(struct device *dev, struct rz_dmac_chan *channel,
> + dma_cookie_t cookie, u32 *residue)
> {
> struct rz_dmac_desc *desc = NULL;
> struct virt_dma_desc *vd;
> @@ -871,7 +871,8 @@ static u32 rz_dmac_chan_get_residue(struct rz_dmac_chan *channel,
> if (vd) {
> /* Descriptor has been issued but not yet processed. */
> desc = to_rz_dmac_desc(vd);
> - return desc->len;
> + *residue = desc->len;
> + return 0;
> } else if (channel->desc && channel->desc->vd.tx.cookie == cookie) {
> /* Descriptor is currently processed. */
> desc = channel->desc;
> @@ -879,6 +880,7 @@ static u32 rz_dmac_chan_get_residue(struct rz_dmac_chan *channel,
>
> if (!desc) {
> /* Descriptor was not found. May be already completed by now. */
> + *residue = 0;
> return 0;
> }
>
> @@ -901,7 +903,9 @@ static u32 rz_dmac_chan_get_residue(struct rz_dmac_chan *channel,
> * Calculate number of bytes transferred in processing virtual descriptor.
> * One virtual descriptor can have many lmdesc.
> */
> - return crtb + rz_dmac_calculate_residue_bytes_in_vd(channel, desc, crla);
> + *residue = crtb + rz_dmac_calculate_residue_bytes_in_vd(channel, desc, crla);
> +
> + return 0;
> }
>
> static enum dma_status rz_dmac_tx_status(struct dma_chan *chan,
> @@ -909,15 +913,20 @@ static enum dma_status rz_dmac_tx_status(struct dma_chan *chan,
> struct dma_tx_state *txstate)
> {
> struct rz_dmac_chan *channel = to_rz_dmac_chan(chan);
> + struct rz_dmac *dmac = to_rz_dmac(chan->device);
> enum dma_status status;
> u32 residue;
>
> scoped_guard(spinlock_irqsave, &channel->vc.lock) {
> + int ret;
> +
> status = dma_cookie_status(chan, cookie, txstate);
> if (status == DMA_COMPLETE || !txstate)
> return status;
>
> - residue = rz_dmac_chan_get_residue(channel, cookie);
> + ret = rz_dmac_chan_get_residue(dmac->dev, channel, cookie, &residue);
> + if (ret)
> + return DMA_ERROR;
>
> if (status == DMA_IN_PROGRESS && rz_dmac_chan_is_paused(channel))
> status = DMA_PAUSED;
> --
> 2.43.0
>