]> git.ipfire.org Git - people/arne_f/kernel.git/commit
dmaengine: Store module owner in dma_device struct
authorLogan Gunthorpe <logang@deltatee.com>
Mon, 16 Dec 2019 19:01:16 +0000 (12:01 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 28 Feb 2020 15:36:01 +0000 (16:36 +0100)
commit35557d209c94eae2be6613141d2f6f9902dc110c
tree75f1b18daff70fe4fe1f7282a8c5b1fb4c4d80d3
parent285f156fc859f0a922173a81af7cc4ccb6ac4b5b
dmaengine: Store module owner in dma_device struct

[ Upstream commit dae7a589c18a4d979d5f14b09374e871b995ceb1 ]

dma_chan_to_owner() dereferences the driver from the struct device to
obtain the owner and call module_[get|put](). However, if the backing
device is unbound before the dma_device is unregistered, the driver
will be cleared and this will cause a NULL pointer dereference.

Instead, store a pointer to the owner module in the dma_device struct
so the module reference can be properly put when the channel is put, even
if the backing device was destroyed first.

This change helps to support a safer unbind of DMA engines.
If the dma_device is unregistered in the driver's remove function,
there's no guarantee that there are no existing clients and a users
action may trigger the WARN_ONCE in dma_async_device_unregister()
which is unlikely to leave the system in a consistent state.
Instead, a better approach is to allow the backing driver to go away
and fail any subsequent requests to it.

Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
Link: https://lore.kernel.org/r/20191216190120.21374-2-logang@deltatee.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/dma/dmaengine.c
include/linux/dmaengine.h