mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Frank Li <Frank.li@oss.nxp.com>
To: Daniel Byrne <daniel1.byrne@intel.com>
Cc: Vinod Koul <vkoul@kernel.org>,
	dmaengine@vger.kernel.org,
	Vinicius Costa Gomes <vinicius.gomes@intel.com>,
	Dave Jiang <dave.jiang@intel.com>, Frank Li <Frank.Li@kernel.org>,
	Dan Williams <djbw@kernel.org>, Ruoyu Wang <ruoyuw560@gmail.com>,
	Zhejun Huang <zhejun_huang@linux.alibaba.com>,
	Changyul Lee <lcy8047@gmail.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/4] dmaengine: put a channel device whose registration failed
Date: Mon, 30 Nov 2026 15:13:00 -0600	[thread overview]
Message-ID: <aw3m3BW9j6giB025@SMW015318> (raw)
In-Reply-To: <20261130195203.1901143-2-daniel1.byrne@intel.com>

On Mon, Nov 30, 2026 at 11:52:00AM -0800, Daniel Byrne wrote:
> __dma_async_device_channel_register() frees a channel's device with
> kfree() when device_register() fails. device_register() has initialized
> the device by then, so its reference has to be dropped with
> put_device(), and the name set by dev_set_name() leaks otherwise.
>
> Drop the reference, and let the release free the device together with
> its name. The channel's id is freed first, since the release does not
> free it, and the ida label that no longer has a user goes away.
>
> The registration of a channel failed with -EEXIST when the channel was
> handed an id whose sysfs device still existed, which "dmaengine: Free
> channel ID after device_unregister()" [1] fixes. The registration can
> still fail for want of memory.
>
> Fixes: 257b17ca0303 ("dmaengine: fail device registration if channel registration fails")
> Signed-off-by: Daniel Byrne <daniel1.byrne@intel.com>
> Link: https://lore.kernel.org/r/20261110101607.13784-1-zhejun_huang@linux.alibaba.com [1]
> ---

Reviewed-by: Frank Li <Frank.Li@nxp.com>

> New in v2.
>
>  drivers/dma/dmaengine.c | 14 ++++++++++----
>  1 file changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
> index 2642abf105d7..b1cb466f376f 100644
> --- a/drivers/dma/dmaengine.c
> +++ b/drivers/dma/dmaengine.c
> @@ -1126,15 +1126,21 @@ static int __dma_async_device_channel_register(struct dma_device *device,
>  	else
>  		dev_set_name(dmaengine_chan_dev(chan), "%s", name);
>  	rc = device_register(dmaengine_chan_dev(chan));
> -	if (rc)
> -		goto err_out_ida;
> +	if (rc) {
> +		/*
> +		 * device_register() initialized the device. Its release
> +		 * frees it, together with the name set above.
> +		 */
> +		ida_free(&device->chan_ida, chan->chan_id);
> +		put_device(dmaengine_chan_dev(chan));
> +		chan->chan_dev = NULL;
> +		goto err_free_local;
> +	}
>  	chan->client_count = 0;
>  	device->chancnt++;
>
>  	return 0;
>
> - err_out_ida:
> -	ida_free(&device->chan_ida, chan->chan_id);
>   err_free_dev:
>  	kfree(chan->chan_dev);
>   err_free_local:
> --
> 2.43.0
>

  reply	other threads:[~2026-11-30 21:13 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 19:51 [PATCH v2 0/4] dmaengine: fixes for channels registered and removed at run time Daniel Byrne
2026-11-30 19:52 ` [PATCH v2 1/4] dmaengine: put a channel device whose registration failed Daniel Byrne
2026-11-30 21:13   ` Frank Li [this message]
2026-11-30 19:52 ` [PATCH v2 2/4] dmaengine: idxd: list a new channel only once it is complete Daniel Byrne
2026-11-30 21:30   ` Frank Li
2026-11-30 19:52 ` [PATCH v2 3/4] dmaengine: idxd: unlink a channel under dma_list_mutex before removing it Daniel Byrne
2026-11-30 21:32   ` Frank Li
2026-11-30 19:52 ` [PATCH v2 4/4] dmaengine: rebalance a dynamically registered channel under dma_list_mutex Daniel Byrne
2026-11-30 22:09   ` Frank Li

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=aw3m3BW9j6giB025@SMW015318 \
    --to=frank.li@oss.nxp.com \
    --cc=Frank.Li@kernel.org \
    --cc=daniel1.byrne@intel.com \
    --cc=dave.jiang@intel.com \
    --cc=djbw@kernel.org \
    --cc=dmaengine@vger.kernel.org \
    --cc=lcy8047@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ruoyuw560@gmail.com \
    --cc=vinicius.gomes@intel.com \
    --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

all inboxes | Powered by JetHome®