On Wed, Nov 23, 2022 at 10:41:08AM +0800, Xiongfeng Wang wrote: > On 2022/11/23 3:03, Andy Shevchenko wrote: > > On Tue, Nov 22, 2022 at 07:45:59PM +0800, Xiongfeng Wang wrote: > >> As comment of pci_get_slot() says, it returns a pci_device with its > >> refcount increased. The caller must decrement the reference count by > >> calling pci_dev_put(). > > > >> Since 'dma_dev' is only used to filter the channel in filter(), we can > >> call pci_dev_put() before exiting from pch_request_dma(). Add the > >> missing pci_dev_put() for the normal and error path. > > > > No, we can't do that. How is it supposed to work if DMA device disappears in > > the middle? > > When the DMA device is registered into the system, its refcount is increased. > dma_request_channel() will increase the refcount for 'dma_chan'. So I think this > can gurantee the DMA device not removed in the middle. It might be the case in this particular driver but not in general, i.e. when driver drops and request channels on demand, like with SPI case. By doing this way you prevent (possible) modifications to serial core to use DMA on demand. That's why I recommend to switch to more robust way of solving this. -- With Best Regards, Andy Shevchenko