mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Frank Li <Frank.li@nxp.com>
To: Maoyi Xie <maoyixie.tju@gmail.com>
Cc: Vinod Koul <vkoul@kernel.org>,
	dmaengine@vger.kernel.org, linux-renesas-soc@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: dmaengine: dead empty checks in mpc512x and rz-dmac descriptor pickup?
Date: Wed, 20 May 2026 17:46:03 -0400	[thread overview]
Message-ID: <ag4rmx2584rYPLv2@lizhi-Precision-Tower-5810> (raw)
In-Reply-To: <20260519190442.2382986-1-maoyixie.tju@gmail.com>

On Wed, May 20, 2026 at 03:04:42AM +0800, Maoyi Xie wrote:
> Hi all,
>
> While auditing list_first_entry callsites, I noticed two places in
> drivers/dma where the developer wrote a NULL check for an empty
> list case but used the unsafe API. The check is dead code. I
> would appreciate it if you could take a look and let me know
> whether these are worth fixing.
>
> Site 1, drivers/dma/mpc512x_dma.c mpc_dma_prep_slave_sg()
> (linux-7.1-rc1, around line 709):
>
>     mdesc = list_first_entry(&mchan->free,
>                                     struct mpc_dma_desc, node);
>     if (!mdesc) {
>             spin_unlock_irqrestore(&mchan->lock, iflags);
>             mpc_dma_process_completed(mdma);
>             return NULL;
>     }
>
>     list_del(&mdesc->node);
>
> list_first_entry() returns container_of(&mchan->free, struct
> mpc_dma_desc, node) when the free list is empty, never NULL. The
> recovery path (drop lock, scan completed list, return NULL) is
> dead code. With an empty free list, the fall through pointer
> aliases &mchan->free. The subsequent list_del() then corrupts
> the head's next and prev links.
>
> Site 2, drivers/dma/sh/rz-dmac.c rz_dmac_chan_get_residue()
> (linux-7.1-rc1, around line 726):
>
>     current_desc = list_first_entry(&channel->ld_active,
>                                     struct rz_dmac_desc, node);
>     if (!current_desc)
>             return 0;
>
> Same shape. ld_active can be empty while a residue query races
> with descriptor completion. The `return 0` shortcut never runs,
> and current_desc is then dereferenced for status processing.
>
> A candidate fix in both cases is a one liner. Switch the API to
> list_first_entry_or_null so the existing NULL guard runs as the
> author intended.
>
> Similar dead empty checks after list_first_entry have been
> cleaned up in the same shape, for example commit fbb8bc408027
> (net: qed: Remove redundant NULL checks after list_first_entry),
> commit c708d3fad421 (crypto: atmel: use list_first_entry_or_null
> to simplify find_dev) and commit 10379171f346 (ksmbd: use
> list_first_entry_or_null for opinfo_get_list). The qed commit
> message describes the exact shape we observe here. These two
> sites appear to be missed by those cleanups.
>
> If this is intentional or already known for either site, please
> disregard. Otherwise I am happy to send a [PATCH] series or to
> leave the fix to you.

Thank check this. Please submit PATCH to fix it.

Frank

>
> Thanks,
> Maoyi Xie
> https://maoyixie.com/

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

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-19 19:04 Maoyi Xie
2026-05-20 21:46 ` Frank Li [this message]

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=ag4rmx2584rYPLv2@lizhi-Precision-Tower-5810 \
    --to=frank.li@nxp.com \
    --cc=dmaengine@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=maoyixie.tju@gmail.com \
    --cc=vkoul@kernel.org \
    /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

all inboxes | Powered by JetHome®