All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ata: pata_ep93xx: fix double-free of DMA channel on error path
@ 2026-07-08  9:27 Chen Changcheng
  2026-07-08  9:35 ` sashiko-bot
  2026-07-08 10:50 ` Arnd Bergmann
  0 siblings, 2 replies; 3+ messages in thread
From: Chen Changcheng @ 2026-07-08  9:27 UTC (permalink / raw)
  To: Damien Le Moal, Niklas Cassel
  Cc: Nikita Shubin, Vinod Koul, Sergey Shtylyov, Arnd Bergmann,
	linux-ide, linux-kernel, Chen Changcheng

In ep93xx_pata_dma_init() error path, when dma_request_chan() for the tx
channel fails, the code jumps to fail_release_rx which releases the rx
channel via dma_release_channel() and then falls through to
fail_release_dma, which calls ep93xx_pata_release_dma(). This causes a
double-free of dma_rx_channel. Additionally, drv_data->dma_tx_channel
holds an ERR_PTR at this point, so ep93xx_pata_release_dma() would also
attempt to dma_release_channel() on it.

Fix by removing the fail_release_rx label and jumping directly to
fail_release_dma instead. Make ep93xx_pata_release_dma() use
IS_ERR_OR_NULL() so that it safely handles channels that may be
ERR_PTR rather than valid pointers.

Fixes: 9963113e3a92 ("ata: pata_ep93xx: add device tree support")
Signed-off-by: Chen Changcheng <chenchangcheng@kylinos.cn>
---
 drivers/ata/pata_ep93xx.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/ata/pata_ep93xx.c b/drivers/ata/pata_ep93xx.c
index 42a24dc51d26..b4fb89481b7e 100644
--- a/drivers/ata/pata_ep93xx.c
+++ b/drivers/ata/pata_ep93xx.c
@@ -629,11 +629,11 @@ static int ep93xx_pata_bus_softreset(struct ata_port *ap, unsigned int devmask,
 
 static void ep93xx_pata_release_dma(struct ep93xx_pata_data *drv_data)
 {
-	if (drv_data->dma_rx_channel) {
+	if (!IS_ERR_OR_NULL(drv_data->dma_rx_channel)) {
 		dma_release_channel(drv_data->dma_rx_channel);
 		drv_data->dma_rx_channel = NULL;
 	}
-	if (drv_data->dma_tx_channel) {
+	if (!IS_ERR_OR_NULL(drv_data->dma_tx_channel)) {
 		dma_release_channel(drv_data->dma_tx_channel);
 		drv_data->dma_tx_channel = NULL;
 	}
@@ -664,7 +664,7 @@ static int ep93xx_pata_dma_init(struct ep93xx_pata_data *drv_data)
 	if (IS_ERR(drv_data->dma_tx_channel)) {
 		ret = dev_err_probe(dev, PTR_ERR(drv_data->dma_tx_channel),
 				    "tx DMA setup failed\n");
-		goto fail_release_rx;
+		goto fail_release_dma;
 	}
 
 	/* Configure receive channel direction and source address */
@@ -691,8 +691,6 @@ static int ep93xx_pata_dma_init(struct ep93xx_pata_data *drv_data)
 
 	return 0;
 
-fail_release_rx:
-	dma_release_channel(drv_data->dma_rx_channel);
 fail_release_dma:
 	ep93xx_pata_release_dma(drv_data);
 
-- 
2.25.1


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

end of thread, other threads:[~2026-07-08 10:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-08  9:27 [PATCH] ata: pata_ep93xx: fix double-free of DMA channel on error path Chen Changcheng
2026-07-08  9:35 ` sashiko-bot
2026-07-08 10:50 ` Arnd Bergmann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.