* [PATCH] dmaengine: switchtec-dma: Fix device reference leak in switchtec_dma_create()
@ 2026-09-16 9:33 Wentao Liang
2026-09-16 16:05 ` Frank Li
0 siblings, 1 reply; 3+ messages in thread
From: Wentao Liang @ 2026-09-16 9:33 UTC (permalink / raw)
To: Frank.Li
Cc: dmaengine, george.ge, kelvin.cao, linux-kernel, logang, vkoul,
Wentao Liang, stable
switchtec_dma_create() takes a reference on the PCI device with
get_device() and stores it in dma->dev. The reference is normally
dropped by switchtec_dma_release(), the device_release() callback,
which only runs after a successful dma_async_device_register(). If
the registration fails, the code frees the dma device directly from
the err_chans_release_exit label without ever dropping that extra
reference, leaking the reference taken on the PCI device.
Drop the reference with put_device() on the error path.
Fixes: d9587042b50f ("dmaengine: switchtec-dma: Introduce Switchtec DMA engine skeleton")
Cc: stable@vger.kernel.org
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
drivers/dma/switchtec_dma.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/dma/switchtec_dma.c b/drivers/dma/switchtec_dma.c
index 3ef928640615..b07bdd0ac540 100644
--- a/drivers/dma/switchtec_dma.c
+++ b/drivers/dma/switchtec_dma.c
@@ -1297,6 +1297,7 @@ static int switchtec_dma_create(struct pci_dev *pdev)
err_chans_release_exit:
switchtec_dma_chans_release(pdev, swdma_dev);
+ put_device(dma->dev);
err_exit:
if (swdma_dev->chan_status_irq)
--
2.34.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] dmaengine: switchtec-dma: Fix device reference leak in switchtec_dma_create()
2026-09-16 9:33 [PATCH] dmaengine: switchtec-dma: Fix device reference leak in switchtec_dma_create() Wentao Liang
@ 2026-09-16 16:05 ` Frank Li
2026-09-16 17:53 ` Logan Gunthorpe
0 siblings, 1 reply; 3+ messages in thread
From: Frank Li @ 2026-09-16 16:05 UTC (permalink / raw)
To: Wentao Liang
Cc: Frank.Li, dmaengine, george.ge, kelvin.cao, linux-kernel, logang,
vkoul, stable
On Wed, Sep 16, 2026 at 09:33:32AM +0000, Wentao Liang wrote:
> switchtec_dma_create() takes a reference on the PCI device with
> get_device() and stores it in dma->dev. The reference is normally
> dropped by switchtec_dma_release(), the device_release() callback,
> which only runs after a successful dma_async_device_register(). If
> the registration fails, the code frees the dma device directly from
> the err_chans_release_exit label without ever dropping that extra
> reference, leaking the reference taken on the PCI device.
>
> Drop the reference with put_device() on the error path.
>
> Fixes: d9587042b50f ("dmaengine: switchtec-dma: Introduce Switchtec DMA engine skeleton")
> Cc: stable@vger.kernel.org
> Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
> ---
> drivers/dma/switchtec_dma.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/dma/switchtec_dma.c b/drivers/dma/switchtec_dma.c
> index 3ef928640615..b07bdd0ac540 100644
> --- a/drivers/dma/switchtec_dma.c
> +++ b/drivers/dma/switchtec_dma.c
> @@ -1297,6 +1297,7 @@ static int switchtec_dma_create(struct pci_dev *pdev)
>
> err_chans_release_exit:
> switchtec_dma_chans_release(pdev, swdma_dev);
> + put_device(dma->dev);
Does switchtec_dma_remove() also need put_device()?
Frank
>
> err_exit:
> if (swdma_dev->chan_status_irq)
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] dmaengine: switchtec-dma: Fix device reference leak in switchtec_dma_create()
2026-09-16 16:05 ` Frank Li
@ 2026-09-16 17:53 ` Logan Gunthorpe
0 siblings, 0 replies; 3+ messages in thread
From: Logan Gunthorpe @ 2026-09-16 17:53 UTC (permalink / raw)
To: Frank Li, Wentao Liang
Cc: Frank.Li, dmaengine, george.ge, kelvin.cao, linux-kernel, vkoul, stable
On 2026-09-16 10:05, Frank Li wrote:
> On Wed, Sep 16, 2026 at 09:33:32AM +0000, Wentao Liang wrote:
>> switchtec_dma_create() takes a reference on the PCI device with
>> get_device() and stores it in dma->dev. The reference is normally
>> dropped by switchtec_dma_release(), the device_release() callback,
>> which only runs after a successful dma_async_device_register(). If
>> the registration fails, the code frees the dma device directly from
>> the err_chans_release_exit label without ever dropping that extra
>> reference, leaking the reference taken on the PCI device.
>>
>> Drop the reference with put_device() on the error path.
>>
>> Fixes: d9587042b50f ("dmaengine: switchtec-dma: Introduce Switchtec DMA engine skeleton")
>> Cc: stable@vger.kernel.org
>> Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
>> ---
>> drivers/dma/switchtec_dma.c | 1 +
>> 1 file changed, 1 insertion(+)
>>
>> diff --git a/drivers/dma/switchtec_dma.c b/drivers/dma/switchtec_dma.c
>> index 3ef928640615..b07bdd0ac540 100644
>> --- a/drivers/dma/switchtec_dma.c
>> +++ b/drivers/dma/switchtec_dma.c
>> @@ -1297,6 +1297,7 @@ static int switchtec_dma_create(struct pci_dev *pdev)
>>
>> err_chans_release_exit:
>> switchtec_dma_chans_release(pdev, swdma_dev);
>> + put_device(dma->dev);
>
> Does switchtec_dma_remove() also need put_device()?
No, the release already happens in switchtec_dma_release() after the
device is removed. It can't be done in swtichtec_dma_remove() or it will
be potentially used if the device still exists after
switchtec_dma_remove() completes.
The patch looks correct to me but it will conflict with the patches in
my series waiting for merging:
https://lore.kernel.org/all/20260902062153.31048-1-logang@deltatee.com/T/#u
I'd appreciate it if my series could go in first and this gets rebased
on top of it.
Other than that:
Reviewed-by: Logan Gunthorpe <logang@deltatee.com>
Thanks!
Logan
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-09-16 17:53 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-16 9:33 [PATCH] dmaengine: switchtec-dma: Fix device reference leak in switchtec_dma_create() Wentao Liang
2026-09-16 16:05 ` Frank Li
2026-09-16 17:53 ` Logan Gunthorpe
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®