dmaengine: add dma_device_get() helper

Add dma_device_get() helper to match dma_device_put() to make code
symmetric. It wraps open-coded kref_get_unless_zero() and asserts that
dma_list_mutex is held, matching its put counterpart.

No functional change intended.

Suggested-by: Frank Li <Frank.Li@nxp.com>
Reviewed-by: Logan Gunthorpe <logang@deltatee.com>
Signed-off-by: Shivank Garg <shivankg@amd.com>
Link: https://patch.msgid.link/20260822-dmaengine-kref-fix-v5-1-d4a4ee47d927@amd.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>
This commit is contained in:
Shivank Garg 2026-08-22 19:22:03 +00:00 committed by Vinod Koul
parent a7df136ec5
commit 424103642d

View File

@ -433,6 +433,12 @@ static void dma_device_release(struct kref *ref)
device->device_release(device);
}
static int __must_check dma_device_get(struct dma_device *device)
{
lockdep_assert_held(&dma_list_mutex);
return kref_get_unless_zero(&device->ref);
}
static void dma_device_put(struct dma_device *device)
{
lockdep_assert_held(&dma_list_mutex);
@ -460,8 +466,7 @@ static int dma_chan_get(struct dma_chan *chan)
if (!try_module_get(owner))
return -ENODEV;
ret = kref_get_unless_zero(&chan->device->ref);
if (!ret) {
if (!dma_device_get(chan->device)) {
ret = -ENODEV;
goto module_put_out;
}