DMA Engine development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: zhejun_huang@linux.alibaba.com
Cc: dmaengine@vger.kernel.org, vkoul@kernel.org, Frank.Li@kernel.org
Subject: Re: [PATCH] dmaengine: Free channel ID after device_unregister()
Date: Tue, 10 Nov 2026 10:31:19 +0000	[thread overview]
Message-ID: <sashiko-outbox-206873@kernel.org> (raw)
In-Reply-To: <20261110101607.13784-1-zhejun_huang@linux.alibaba.com>

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Medium] dmaengine: IDA leak on error path in
  dma_async_device_register() [1]
--

commit e2b5dc17e7cb70401abfdf640998b8028522d873
Author: Zhejun Huang <zhejun_huang@linux.alibaba.com>

dmaengine: Free channel ID after device_unregister()

This commit moves the ida_free() call in
__dma_async_device_channel_unregister() after device_unregister() so that a
concurrent channel registration cannot reuse the channel ID before the old
device name is removed.

> diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
> index 34be53487a21d..2642abf105d76 100644
> --- a/drivers/dma/dmaengine.c
> +++ b/drivers/dma/dmaengine.c
> @@ -1171,8 +1171,8 @@ static void __dma_async_device_channel_unregister(struct dma_device *device,
>  	device->chancnt--;
>  	chan->chan_dev->chan = NULL;
>  	mutex_unlock(&dma_list_mutex);
> -	ida_free(&device->chan_ida, chan->chan_id);
>  	device_unregister(dmaengine_chan_dev(chan));
> +	ida_free(&device->chan_ida, chan->chan_id);
>  	free_percpu(chan->local);
>  }

[Severity: Medium]
This problem wasn't introduced by this patch, but does the error path in
dma_async_device_register() leak IDs from device->chan_ida and dma_ida
[1]?

drivers/dma/dmaengine.c:dma_async_device_register() {
    ...
err_out:
	/* if we never registered a channel just release the idr */
	if (!device->chancnt) {
		ida_free(&dma_ida, device->dev_id);
		return rc;
	}

	list_for_each_entry(chan, &device->channels, device_node) {
		if (chan->local == NULL)
			continue;
		mutex_lock(&dma_list_mutex);
		chan->chan_dev->chan = NULL;
		mutex_unlock(&dma_list_mutex);
		device_unregister(dmaengine_chan_dev(chan));
		free_percpu(chan->local);
	}
	return rc;
}

If registration fails after at least one channel has been registered (for
example, on a subsequent channel or in dma_chan_get()), device->chancnt is
non-zero.  The open-coded cleanup loop unregisters the channels without
freeing each chan->chan_id or destroying device->chan_ida, and
device->dev_id is never freed from dma_ida.

[1] https://sashiko.dev/#/bug/linux-39bbcde3-023e-41e2-afef-7a2c13f45a17

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261110101607.13784-1-zhejun_huang@linux.alibaba.com?part=1

  reply	other threads:[~2026-11-10 10:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-10 10:16 [PATCH] dmaengine: Free channel ID after device_unregister() zhejun_huang
2026-11-10 10:31 ` sashiko-bot [this message]
2026-11-10 14:51 ` Frank Li
2026-11-11  3:37 ` Yao Yuan

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=sashiko-outbox-206873@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=dmaengine@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=vkoul@kernel.org \
    --cc=zhejun_huang@linux.alibaba.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