[PATCH v2] iio: adc: ti_am335x_adc: Fix potential use-after-free on DMA unbind

From: Guangshuo Li

Date: Tue Nov 24 2026 - 08:58:43 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>
---
Changes in v2:
- Use dmaengine_get_provider_device() to obtain the supplier device.

Backports need 61527d7e6998 ("dmaengine: add dmaengine_get_provider_device() API").

drivers/iio/adc/ti_am335x_adc.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/drivers/iio/adc/ti_am335x_adc.c b/drivers/iio/adc/ti_am335x_adc.c
index 0c3e0e9e8364..c7f8bafe0f4a 100644
--- a/drivers/iio/adc/ti_am335x_adc.c
+++ b/drivers/iio/adc/ti_am335x_adc.c
@@ -546,6 +546,11 @@ static int tiadc_request_dma(struct platform_device *pdev,
return ret;
}

+ if (!device_link_add(&pdev->dev,
+ dmaengine_get_provider_device(dma->chan),
+ 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: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f
--
2.43.0