DMA Engine development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Maoyi Xie" <maoyixie.tju@gmail.com>
Cc: dmaengine@vger.kernel.org, Frank.Li@kernel.org, vkoul@kernel.org,
	wsa+renesas@sang-engineering.com
Subject: Re: [PATCH 2/2] dmaengine: rz-dmac: fix dead empty check in rz_dmac_chan_get_residue()
Date: Thu, 21 May 2026 16:05:00 +0000	[thread overview]
Message-ID: <20260521160500.A49DB1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260521144755.3476353-3-maoyixie.tju@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

New issues:
- [High] The patch introduces a logic error that falsely reports pending unissued transfers as DMA_COMPLETE.

Pre-existing issues:
- [High] Race condition where unsubmitted descriptors are prematurely executed by the hardware.
--

commit 0e410e8d5063eb51746f71d6bfff0bc38f086e9b
Author: Maoyi Xie <maoyixie.tju@gmail.com>
Subject: dmaengine: rz-dmac: fix dead empty check in rz_dmac_chan_get_residue()

This commit changes list_first_entry to list_first_entry_or_null in
rz_dmac_chan_get_residue to properly check if the active list is empty.
If the list is empty, it now safely returns a zero residue instead of
reading from invalid neighboring memory.

> diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c
> index 625ff29024de0..3dd76615881ff 100644
> --- a/drivers/dma/sh/rz-dmac.c
> +++ b/drivers/dma/sh/rz-dmac.c
> @@ -723,8 +723,8 @@ static u32 rz_dmac_chan_get_residue(struct rz_dmac_chan *channel,
>  	u32 crla, crtb, i;
>  
>  	/* Get current processing virtual descriptor */
> -	current_desc = list_first_entry(&channel->ld_active,
> -					struct rz_dmac_desc, node);
> +	current_desc = list_first_entry_or_null(&channel->ld_active,
> +						struct rz_dmac_desc, node);
>  	if (!current_desc)
>  		return 0;

[Severity: High]
If a client queries the status of a transfer that has been prepared but not
yet issued, or while it is pending in ld_queue waiting for previous
transfers, ld_active will be empty. With this patch, current_desc will be
null and the function will immediately return 0.

Does returning 0 residue here cause rz_dmac_tx_status() to prematurely
report the transfer as finished with a DMA_COMPLETE status?

Before this patch, the invalid pointer coincidentally bypassed the null
check, which allowed the code to continue, correctly search ld_queue, and
return the full descriptor length. Returning early here could cause
clients to free or reuse buffers while the hardware is still scheduled to
access them.

[Severity: High]
This is a pre-existing issue, but looking at how descriptors are queued,
is there a race condition where unsubmitted descriptors are prematurely
executed by the hardware?

In rz_dmac_prep_slave_sg() and rz_dmac_prep_dma_memcpy(), prepared
descriptors are immediately placed into channel->ld_queue before the
client calls dmaengine_submit(). If an existing transfer completes, the
hardware interrupt handler rz_dmac_irq_handler_thread() appears to blindly
pull the next descriptor from ld_queue and initiates the transfer via
rz_dmac_xfer_desc().

Could this result in the hardware executing transfers before the client
has filled the data buffers or actually submitted the transfer?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260521144755.3476353-1-maoyixie.tju@gmail.com?part=2

  reply	other threads:[~2026-05-21 16:05 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-21 14:47 [PATCH 0/2] dmaengine: fix dead empty checks in mpc512x and rz-dmac Maoyi Xie
2026-05-21 14:47 ` [PATCH 1/2] dmaengine: mpc512x: fix dead empty check in mpc_dma_prep_slave_sg() Maoyi Xie
2026-05-21 15:42   ` sashiko-bot
2026-05-21 16:30   ` Frank Li
2026-05-22 15:02   ` [PATCH v2] " Maoyi Xie
2026-05-22 15:23     ` sashiko-bot
2026-05-21 14:47 ` [PATCH 2/2] dmaengine: rz-dmac: fix dead empty check in rz_dmac_chan_get_residue() Maoyi Xie
2026-05-21 16:05   ` sashiko-bot [this message]
2026-05-22  8:16   ` Geert Uytterhoeven
2026-05-22  8:37     ` Maoyi Xie

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260521160500.A49DB1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=dmaengine@vger.kernel.org \
    --cc=maoyixie.tju@gmail.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=vkoul@kernel.org \
    --cc=wsa+renesas@sang-engineering.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox