Linux ATA/IDE development
 help / color / mirror / Atom feed
* [PATCH] ata: sata_dwc_460ex: Fix DMA channel leak in sata_dwc_port_start()
@ 2026-11-17  9:49 Haoxiang Li
  2026-11-17  9:54 ` sashiko-bot
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Haoxiang Li @ 2026-11-17  9:49 UTC (permalink / raw)
  To: dlemoal, cassel, mans, tj; +Cc: linux-ide, linux-kernel, Haoxiang Li

If phy_power_on() fails in sata_dwc_port_start(), the error path
frees hsdevp without releasing the DMA channel acquired earlier.
Add a cleanup label to release the DMA channel before freeing
hsdevp on this failure path.

Fixes: 0f48debdb906 ("ata: sata_dwc_460ex: add phy support")
Signed-off-by: Haoxiang Li <haoxiang_li2024@163.com>
---
 drivers/ata/sata_dwc_460ex.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/ata/sata_dwc_460ex.c b/drivers/ata/sata_dwc_460ex.c
index 486ea94a0184..c1025ab3e474 100644
--- a/drivers/ata/sata_dwc_460ex.c
+++ b/drivers/ata/sata_dwc_460ex.c
@@ -853,7 +853,7 @@ static int sata_dwc_port_start(struct ata_port *ap)
 
 	err = phy_power_on(hsdev->phy);
 	if (err)
-		goto CLEANUP_ALLOC;
+		goto CLEANUP_DMA;
 
 	for (i = 0; i < SATA_DWC_QCMD_MAX; i++)
 		hsdevp->cmd_issued[i] = SATA_DWC_CMD_ISSUED_NOT;
@@ -880,6 +880,8 @@ static int sata_dwc_port_start(struct ata_port *ap)
 	dev_dbg(ap->dev, "%s: done\n", __func__);
 	return 0;
 
+CLEANUP_DMA:
+	dma_release_channel(hsdevp->chan);
 CLEANUP_ALLOC:
 	kfree(hsdevp);
 CLEANUP:
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] ata: sata_dwc_460ex: Fix DMA channel leak in sata_dwc_port_start()
  2026-11-17  9:49 [PATCH] ata: sata_dwc_460ex: Fix DMA channel leak in sata_dwc_port_start() Haoxiang Li
@ 2026-11-17  9:54 ` sashiko-bot
  2026-11-17 12:05 ` Damien Le Moal
  2026-11-17 12:38 ` Niklas Cassel
  2 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-11-17  9:54 UTC (permalink / raw)
  To: Haoxiang Li; +Cc: linux-ide, dlemoal, cassel

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:
- [Critical] ata: sata_dwc_460ex: use-after-free in sata_dwc_probe() [1]
--

commit 7cbed05368af81c2d62d6074918f0d6f1dc52c91
Author: Haoxiang Li <haoxiang_li2024@163.com>

ata: sata_dwc_460ex: Fix DMA channel leak in sata_dwc_port_start()

This commit releases the DMA channel in sata_dwc_port_start() when
phy_power_on() fails before freeing the port structure.

> diff --git a/drivers/ata/sata_dwc_460ex.c b/drivers/ata/sata_dwc_460ex.c
> index 0daa5850a7bd0..4ab378d2c26f7 100644
> --- a/drivers/ata/sata_dwc_460ex.c
> +++ b/drivers/ata/sata_dwc_460ex.c
> @@ -852,7 +852,7 @@ static int sata_dwc_port_start(struct ata_port *ap)
>  
>  	err = phy_power_on(hsdev->phy);
>  	if (err)
> -		goto CLEANUP_ALLOC;
> +		goto CLEANUP_DMA;
>  
>  	for (i = 0; i < SATA_DWC_QCMD_MAX; i++)
>  		hsdevp->cmd_issued[i] = SATA_DWC_CMD_ISSUED_NOT;
> @@ -879,6 +879,8 @@ static int sata_dwc_port_start(struct ata_port *ap)
>  	dev_dbg(ap->dev, "%s: done\n", __func__);
>  	return 0;
>  
> +CLEANUP_DMA:
> +	dma_release_channel(hsdevp->chan);
>  CLEANUP_ALLOC:
>  	kfree(hsdevp);
>  CLEANUP:

[Severity: Critical]
This problem wasn't introduced by this patch, but can a failure in
sata_dwc_probe() after sata_dwc_dma_init_old() cause a use-after-free
[1] on the shared interrupt line?

drivers/ata/sata_dwc_460ex.c:sata_dwc_probe() {
	...
#ifdef CONFIG_SATA_DWC_OLD_DMA
	if (!of_property_present(dev->of_node, "dmas")) {
		err = sata_dwc_dma_init_old(ofdev, hsdev);
		if (err)
			return err;
	}
#endif

	hsdev->phy = devm_phy_optional_get(dev, "sata-phy");
	if (IS_ERR(hsdev->phy))
		return PTR_ERR(hsdev->phy);

	err = phy_init(hsdev->phy);
	if (err)
		goto error_out;
	...
error_out:
	phy_exit(hsdev->phy);
	return err;
}

sata_dwc_dma_init_old() registers a DMA engine and requests a shared
interrupt without devres, but the subsequent error paths in
sata_dwc_probe() return without calling sata_dwc_dma_exit_old().  When
probe fails, the driver core frees the devm-allocated device context while
the shared interrupt remains registered, so a later interrupt on that line
invokes the handler with freed memory.

[1] https://sashiko.dev/#/bug/linux-4f29918f-8b5f-48b5-ab4d-aa40ae6890e7

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117094903.1282096-1-haoxiang_li2024@163.com?part=1

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] ata: sata_dwc_460ex: Fix DMA channel leak in sata_dwc_port_start()
  2026-11-17  9:49 [PATCH] ata: sata_dwc_460ex: Fix DMA channel leak in sata_dwc_port_start() Haoxiang Li
  2026-11-17  9:54 ` sashiko-bot
@ 2026-11-17 12:05 ` Damien Le Moal
  2026-11-17 12:38 ` Niklas Cassel
  2 siblings, 0 replies; 4+ messages in thread
From: Damien Le Moal @ 2026-11-17 12:05 UTC (permalink / raw)
  To: Haoxiang Li, cassel, mans, tj; +Cc: linux-ide, linux-kernel

On 11/17/26 01:49, Haoxiang Li wrote:
> If phy_power_on() fails in sata_dwc_port_start(), the error path
> frees hsdevp without releasing the DMA channel acquired earlier.
> Add a cleanup label to release the DMA channel before freeing
> hsdevp on this failure path.
> 
> Fixes: 0f48debdb906 ("ata: sata_dwc_460ex: add phy support")
> Signed-off-by: Haoxiang Li <haoxiang_li2024@163.com>

Looks good.

Reviewed-by: Damien Le Moal <dlemoal@kernel.org>


-- 
Damien Le Moal
Western Digital Research

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] ata: sata_dwc_460ex: Fix DMA channel leak in sata_dwc_port_start()
  2026-11-17  9:49 [PATCH] ata: sata_dwc_460ex: Fix DMA channel leak in sata_dwc_port_start() Haoxiang Li
  2026-11-17  9:54 ` sashiko-bot
  2026-11-17 12:05 ` Damien Le Moal
@ 2026-11-17 12:38 ` Niklas Cassel
  2 siblings, 0 replies; 4+ messages in thread
From: Niklas Cassel @ 2026-11-17 12:38 UTC (permalink / raw)
  To: dlemoal, mans, tj, Haoxiang Li; +Cc: linux-ide, linux-kernel

On Tue, 17 Nov 2026 17:49:03 +0800, Haoxiang Li wrote:
> If phy_power_on() fails in sata_dwc_port_start(), the error path
> frees hsdevp without releasing the DMA channel acquired earlier.
> Add a cleanup label to release the DMA channel before freeing
> hsdevp on this failure path.
> 
> 

Applied to libata/linux.git (for-7.5), thanks!

[1/1] ata: sata_dwc_460ex: Fix DMA channel leak in sata_dwc_port_start()
      https://git.kernel.org/libata/linux/c/9397e8e9

Kind regards,
Niklas


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-17 12:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-17  9:49 [PATCH] ata: sata_dwc_460ex: Fix DMA channel leak in sata_dwc_port_start() Haoxiang Li
2026-11-17  9:54 ` sashiko-bot
2026-11-17 12:05 ` Damien Le Moal
2026-11-17 12:38 ` Niklas Cassel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox