[PATCH v2 3/3] dmaengine: add union chan_dev for dma_chan::dev for clarity

Andy Shevchenko andriy.shevchenko at linux.intel.com
Fri Sep 4 02:19:08 PDT 2026


On Thu, Sep 03, 2026 at 04:53:13PM -0400, Frank.Li at oss.nxp.com wrote:

> The current dma_chan structure contains both "device" and "dev". So
> 
> chan->device->dev refers to the DMA engine device.
> chan->dev->device refers to the per-channel device instance.
> 
> Their similar naming makes the distinction unclear and increases reader
> confusion.
> 
> Add union dma_chan::chan_dev to make its purpose explicit and clearly
> identify it as the per-channel device. After all user switch to chan_dev,
> union and dma_chan::dev will be removed.
> 
> Update the kernel-doc accordingly. Besides its sysfs usage, the per-channel
> device is also used by some DMA engine drivers for IOMMU mapping and
> therefore deserves a more accurate description.
> 
> No functional change intended.

...

>  static inline struct device *chan2dev(struct axi_dma_chan *chan)
>  {
> -	return &chan->vc.chan.dev->device;
> +	return &chan->vc.chan.chan_dev->device;
>  }

Looking at this and below I think we need a common helper(s)

>  static struct device *chan2dev(struct loongson2_cmc_dma_chan *lchan)
>  {
> -	return &lchan->vchan.chan.dev->device;
> +	return &lchan->vchan.chan.chan_dev->device;
>  }

>  	({								\
>  		u32 _v;							\
>  		_v = readl_relaxed((phy)->base + _reg((phy)->idx));	\
> -		dev_vdbg(&phy->vchan->vc.chan.dev->device,		\
> +		dev_vdbg(&phy->vchan->vc.chan.chan_dev->device,		\
>  			 "%s(): readl(%s): 0x%08x\n", __func__, #_reg,	\
>  			  _v);						\
>  		_v;							\

>  #define phy_writel(phy, val, _reg)					\
>  	do {								\
>  		writel((val), (phy)->base + _reg((phy)->idx));		\
> -		dev_vdbg(&phy->vchan->vc.chan.dev->device,		\
> +		dev_vdbg(&phy->vchan->vc.chan.chan_dev->device,		\
>  			 "%s(): writel(0x%08x, %s)\n",			\
>  			 __func__, (u32)(val), #_reg);			\
>  	} while (0)
>  #define phy_writel_relaxed(phy, val, _reg)				\
>  	do {								\
>  		writel_relaxed((val), (phy)->base + _reg((phy)->idx));	\
> -		dev_vdbg(&phy->vchan->vc.chan.dev->device,		\
> +		dev_vdbg(&phy->vchan->vc.chan.chan_dev->device,		\
>  			 "%s(): writel_relaxed(0x%08x, %s)\n",		\
>  			 __func__, (u32)(val), #_reg);			\
>  	} while (0)

>  out_unlock:
>  	spin_unlock_irqrestore(&pdev->phy_lock, flags);
> -	dev_dbg(&pchan->vc.chan.dev->device,
> +	dev_dbg(&pchan->vc.chan.chan_dev->device,
>  		"%s(): phy=%p(%d)\n", __func__, found,
>  		found ? found->idx : -1);
>  

> -	dev_dbg(&chan->vc.chan.dev->device,
> +	dev_dbg(&chan->vc.chan.chan_dev->device,
>  		"%s(): freeing\n", __func__);

> -	dev_dbg(&phy->vchan->vc.chan.dev->device,
> +	dev_dbg(&phy->vchan->vc.chan.chan_dev->device,
>  		"%s(); phy=%p(%d) misaligned=%d\n", __func__,
>  		phy, phy->idx, misaligned);

> -	dev_dbg(&phy->vchan->vc.chan.dev->device,
> +	dev_dbg(&phy->vchan->vc.chan.chan_dev->device,
>  		"%s(): phy=%p(%d)\n", __func__, phy, phy->idx);

> -	dev_dbg(&chan->vc.chan.dev->device,
> +	dev_dbg(&chan->vc.chan.chan_dev->device,
>  		"%s(): desc=%p\n", __func__, desc);
>  	if (!chan->phy) {
>  		chan->phy = lookup_phy(chan);
>  		if (!chan->phy) {
> -			dev_dbg(&chan->vc.chan.dev->device,
> +			dev_dbg(&chan->vc.chan.chan_dev->device,
>  				"%s(): no free dma channel\n", __func__);
>  			return;

(and so on in this PXA driver)

Besides that we should drop __func__ from all _dbg() messages, that can be
enabled run-time with help of Dynamic Debug.

So I think this driver requires more prerequisite work.

>  static struct device *chan2dev(struct stm32_dma_chan *chan)
>  {
> -	return &chan->vchan.chan.dev->device;
> +	return &chan->vchan.chan.chan_dev->device;
>  }

>  static struct device *chan2dev(struct stm32_dma3_chan *chan)
>  {
> -	return &chan->vchan.chan.dev->device;
> +	return &chan->vchan.chan.chan_dev->device;
>  }

>  static struct device *chan2dev(struct stm32_mdma_chan *chan)
>  {
> -	return &chan->vchan.chan.dev->device;
> +	return &chan->vchan.chan.chan_dev->device;
>  }

...

Something like

vchan_to_device(vchan)
{
	return &vchan->chan.chan_dev->device;
}



-- 
With Best Regards,
Andy Shevchenko





More information about the linux-arm-kernel mailing list