iio: use dmaengine_get_dma_device() instead of chan->device->dev
Subsystems (5)
PATCH 1/1 iio: use dmaengine_get_dma_device() instead of chan->device->dev
From: Frank Li <[email protected]>
Replace direct dma_chan::device::dev access with the proper dmaengine_get_dma_device() accessor in IIO DMA consumers.
chan->device->dev is not always the device used for DMA mapping. Some DMA engines support per-channel IOMMU mappings, so different channels may use different DMA devices. dmaengine_get_dma_device() returns the correct device for each channel.
This also prepares for making the DMA engine provider data structures private. DMA consumers should not access DMA engine internals directly.
---
Cc: [email protected]
Cc: [email protected]
--- drivers/iio/adc/at91-sama5d2_adc.c | 9 ++++++--- drivers/iio/adc/nxp-sar-adc.c | 2 +- drivers/iio/adc/stm32-adc.c | 10 ++++++---- drivers/iio/adc/stm32-dfsdm-adc.c | 4 ++-- drivers/iio/adc/ti_am335x_adc.c | 4 ++-- drivers/iio/buffer/industrialio-buffer-dmaengine.c | 5 +++-- 6 files changed, 20 insertions(+), 14 deletions(-)
drivers/iio/adc/at91-sama5d2_adc.c +6 -3
@@ -2016,6 +2016,8 @@ static void at91_adc_dma_init(struct at91_adc_state *st)unsigned int pages =DIV_ROUND_UP (AT91_HWFIFO_MAX_SIZE * sample_size *2 ,PAGE_SIZE ); +struct device *dma_dev; +if (st->dma_st.dma_chan)return ;
@@ -2026,7 +2028,8 @@ static void at91_adc_dma_init(struct at91_adc_state *st) goto dma_exit; } - st->dma_st.rx_buf =dma_alloc_coherent (st->dma_st.dma_chan->device->dev, + dma_dev =dmaengine_get_dma_device (st->dma_st.dma_chan); + st->dma_st.rx_buf =dma_alloc_coherent (dma_dev, pages *PAGE_SIZE , &st->dma_st.rx_dma_buf,GFP_KERNEL );
@@ -2054,7 +2057,7 @@ static void at91_adc_dma_init(struct at91_adc_state *st)return ; dma_free_area: -dma_free_coherent (st->dma_st.dma_chan->device->dev, pages *PAGE_SIZE , +dma_free_coherent (dma_dev, pages *PAGE_SIZE , st->dma_st.rx_buf, st->dma_st.rx_dma_buf); dma_chan_disable:dma_release_channel (st->dma_st.dma_chan);
@@ -2078,7 +2081,7 @@ static void at91_adc_dma_disable(struct at91_adc_state *st)/* wait for all transactions to be terminated first*/ dmaengine_terminate_sync (st->dma_st.dma_chan); -dma_free_coherent (st->dma_st.dma_chan->device->dev, pages *PAGE_SIZE , +dma_free_coherent (dmaengine_get_dma_device (st->dma_st.dma_chan), pages *PAGE_SIZE , st->dma_st.rx_buf, st->dma_st.rx_dma_buf);dma_release_channel (st->dma_st.dma_chan); st->dma_st.dma_chan =NULL ;
drivers/iio/adc/nxp-sar-adc.c +1 -1
@@ -604,7 +604,7 @@ static void nxp_sar_adc_dma_cb(void *data) dma_buf = &info->dma_buf; dma_samples = (u32 *)dma_buf->buf; - dev_dma = info->dma_chan->device->dev; + dev_dma =dmaengine_get_dma_device (info->dma_chan);/* * DMA in some corner cases might have already be charged for
drivers/iio/adc/stm32-adc.c +6 -4
@@ -2456,6 +2456,7 @@ static int stm32_adc_dma_request(struct device *dev, struct iio_dev *indio_dev) {struct stm32_adc *adc =iio_priv (indio_dev);struct dma_slave_config config = { }; +struct device *dma_dev;int ret; adc->dma_chan =dma_request_chan (dev,"rx" );
@@ -2470,7 +2471,8 @@ static int stm32_adc_dma_request(struct device *dev, struct iio_dev *indio_dev)return 0 ; } - adc->rx_buf =dma_alloc_coherent (adc->dma_chan->device->dev, + dma_dev =dmaengine_get_dma_device (adc->dma_chan); + adc->rx_buf =dma_alloc_coherent (dma_dev,STM32_DMA_BUFFER_SIZE , &adc->rx_dma_buf,GFP_KERNEL );if (!adc->rx_buf) {
@@ -2490,7 +2492,7 @@ static int stm32_adc_dma_request(struct device *dev, struct iio_dev *indio_dev)return 0 ; err_free: -dma_free_coherent (adc->dma_chan->device->dev,STM32_DMA_BUFFER_SIZE , +dma_free_coherent (dma_dev,STM32_DMA_BUFFER_SIZE , adc->rx_buf, adc->rx_dma_buf); err_release:dma_release_channel (adc->dma_chan);
@@ -2617,7 +2619,7 @@ static int stm32_adc_probe(struct platform_device *pdev) err_dma_disable:if (adc->dma_chan) { -dma_free_coherent (adc->dma_chan->device->dev, +dma_free_coherent (dmaengine_get_dma_device (adc->dma_chan),STM32_DMA_BUFFER_SIZE , adc->rx_buf, adc->rx_dma_buf);dma_release_channel (adc->dma_chan);
@@ -2640,7 +2642,7 @@ static void stm32_adc_remove(struct platform_device *pdev)pm_runtime_put_noidle (&pdev->dev);iio_triggered_buffer_cleanup (indio_dev);if (adc->dma_chan) { -dma_free_coherent (adc->dma_chan->device->dev, +dma_free_coherent (dmaengine_get_dma_device (adc->dma_chan),STM32_DMA_BUFFER_SIZE , adc->rx_buf, adc->rx_dma_buf);dma_release_channel (adc->dma_chan);
drivers/iio/adc/stm32-dfsdm-adc.c +2 -2
@@ -1484,7 +1484,7 @@ static void stm32_dfsdm_dma_release(struct iio_dev *indio_dev)struct stm32_dfsdm_adc *adc =iio_priv (indio_dev);if (adc->dma_chan) { -dma_free_coherent (adc->dma_chan->device->dev, +dma_free_coherent (dmaengine_get_dma_device (adc->dma_chan),DFSDM_DMA_BUFFER_SIZE , adc->rx_buf, adc->dma_buf);dma_release_channel (adc->dma_chan);
@@ -1504,7 +1504,7 @@ static int stm32_dfsdm_dma_request(struct device *dev,return ret; } - adc->rx_buf =dma_alloc_coherent (adc->dma_chan->device->dev, + adc->rx_buf =dma_alloc_coherent (dmaengine_get_dma_device (adc->dma_chan),DFSDM_DMA_BUFFER_SIZE , &adc->dma_buf,GFP_KERNEL );if (!adc->rx_buf) {
drivers/iio/adc/ti_am335x_adc.c +2 -2
@@ -548,7 +548,7 @@ static int tiadc_request_dma(struct platform_device *pdev, }/* RX buffer */ - dma->buf =dma_alloc_coherent (dma->chan->device->dev,DMA_BUFFER_SIZE , + dma->buf =dma_alloc_coherent (dmaengine_get_dma_device (dma->chan),DMA_BUFFER_SIZE , &dma->addr,GFP_KERNEL );if (!dma->buf) goto err;
@@ -688,7 +688,7 @@ static void tiadc_remove(struct platform_device *pdev)u32 step_en;if (dma->chan) { -dma_free_coherent (dma->chan->device->dev,DMA_BUFFER_SIZE , +dma_free_coherent (dmaengine_get_dma_device (dma->chan),DMA_BUFFER_SIZE , dma->buf, dma->addr);dma_release_channel (dma->chan); }
drivers/iio/buffer/industrialio-buffer-dmaengine.c +3 -2
@@ -254,6 +254,7 @@ static const struct iio_dev_attr *iio_dmaengine_buffer_attrs[] = {*/ static struct iio_buffer *iio_dmaengine_buffer_alloc (struct dma_chan *chan) { +struct device *dma_dev =dmaengine_get_dma_device (chan);struct dmaengine_buffer *dmaengine_buffer;unsigned int width, src_width, dest_width;struct dma_slave_caps caps;
@@ -281,9 +282,9 @@ static struct iio_buffer *iio_dmaengine_buffer_alloc(struct dma_chan *chan)INIT_LIST_HEAD (&dmaengine_buffer->active); dmaengine_buffer->chan = chan; dmaengine_buffer->align = width; - dmaengine_buffer->max_size =dma_get_max_seg_size (chan->device->dev); + dmaengine_buffer->max_size =dma_get_max_seg_size (dma_dev); -iio_dma_buffer_init (&dmaengine_buffer->queue, chan->device->dev, +iio_dma_buffer_init (&dmaengine_buffer->queue, dma_dev, &iio_dmaengine_default_ops); dmaengine_buffer->queue.buffer.attrs = iio_dmaengine_buffer_attrs;
Signature · 1 line
2.43.0
Quoted 10 lines · On Thu, Sep 17, 2026 at 04:36:26PM -0400, [email protected] wrote:
Replace direct
dma_chan::device::devaccess with the properdmaengine_get_dma_device()accessor in IIO DMA consumers.
chan->device->devis not always the device used for DMA mapping. Some DMA engines support per-channel IOMMU mappings, so different channels may use different DMA devices.dmaengine_get_dma_device()returns the correct device for each channel.This also prepares for making the DMA engine provider data structures private. DMA consumers should not access DMA engine internals directly.
...
Quoted 6 lines
drivers/iio/adc/at91-sama5d2_adc.c | 9 ++++++--- drivers/iio/adc/nxp-sar-adc.c | 2 +- drivers/iio/adc/stm32-adc.c | 10 ++++++---- drivers/iio/adc/stm32-dfsdm-adc.c | 4 ++-- drivers/iio/adc/ti_am335x_adc.c | 4 ++-- drivers/iio/buffer/industrialio-buffer-dmaengine.c | 5 +++--
Strictly speaking this is two patches, one per ADC folder and the other against IIO core. But this one is not a big one, so up to Jonathan.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Jonathan Cameron
maintainerQuoted 22 lines · On Fri, 18 Sep 2026 09:47:24 +0300 Andy Shevchenko…
Quoted 10 lines · On Thu, Sep 17, 2026 at 04:36:26PM -0400, [email protected] wrote:
Replace direct
dma_chan::device::devaccess with the properdmaengine_get_dma_device()accessor in IIO DMA consumers.
chan->device->devis not always the device used for DMA mapping. Some DMA engines support per-channel IOMMU mappings, so different channels may use different DMA devices.dmaengine_get_dma_device()returns the correct device for each channel.This also prepares for making the DMA engine provider data structures private. DMA consumers should not access DMA engine internals directly.
...
Quoted 6 lines
drivers/iio/adc/at91-sama5d2_adc.c | 9 ++++++--- drivers/iio/adc/nxp-sar-adc.c | 2 +- drivers/iio/adc/stm32-adc.c | 10 ++++++---- drivers/iio/adc/stm32-dfsdm-adc.c | 4 ++-- drivers/iio/adc/ti_am335x_adc.c | 4 ++-- drivers/iio/buffer/industrialio-buffer-dmaengine.c | 5 +++--
Quoted 2 lines
Strictly speaking this is two patches, one per ADC folder and the other against IIO core. But this one is not a big one, so up to Jonathan.
Agreed that would be ideal but I don't care enough for a v2!
Quoted 2 lines
Reviewed-by Andy Shevchenko <[email protected]>
Applied to the testing branch of iio.git (material for next merge window) That will turn up in linux-next once tests are done and I remember to push.
Thanks,
Jonathan
Quoted 1 line
Quoted 10 lines · On 17-09-26, 16:36, [email protected] wrote:
From: Frank Li <[email protected]>
Replace direct
dma_chan::device::devaccess with the properdmaengine_get_dma_device()accessor in IIO DMA consumers.
chan->device->devis not always the device used for DMA mapping. Some DMA engines support per-channel IOMMU mappings, so different channels may use different DMA devices.dmaengine_get_dma_device()returns the correct device for each channel.
Quoted 5 lines
This also prepares for making the DMA engine provider data structures private. DMA consumers should not access DMA engine internals directly.
Assisted-by LLMSigned-off-by Frank Li <[email protected]>
Signature · 1 line
~Vinod