[PATCH] iio: adc: ti_am335x_adc: Fix potential use-after-free on DMA unbind
From: Guangshuo Li
Date: Wed Nov 18 2026 - 09:27:17 EST
A channel reference does not keep the DMA provider bound. If the EDMA
provider is unbound first, ADC removal accesses the freed channel when
freeing its DMA buffer and releasing the channel.
Link the ADC platform device to the provider so the ADC is removed first,
including when firmware device links are disabled. The driver core drops
the link on probe failure or ADC removal.
This issue was found by our static analysis tool under development.
Fixes: f438b9da75eb ("drivers: iio: ti_am335x_adc: add dma support")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Guangshuo Li <liguangshuo@xxxxxxxxxxxxxxx>
---
drivers/iio/adc/ti_am335x_adc.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/iio/adc/ti_am335x_adc.c b/drivers/iio/adc/ti_am335x_adc.c
index e53c839e87ef..07d6dc7f0355 100644
--- a/drivers/iio/adc/ti_am335x_adc.c
+++ b/drivers/iio/adc/ti_am335x_adc.c
@@ -547,6 +547,10 @@ static int tiadc_request_dma(struct platform_device *pdev,
return ret;
}
+ if (!device_link_add(&pdev->dev, dma->chan->device->dev,
+ DL_FLAG_AUTOREMOVE_CONSUMER))
+ goto err;
+
/* RX buffer */
dma->buf = dma_alloc_coherent(dmaengine_get_dma_device(dma->chan), DMA_BUFFER_SIZE,
&dma->addr, GFP_KERNEL);
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
--
2.43.0