From ed7a856cf76d249d8f899b58b45bf18f2bf63474 Mon Sep 17 00:00:00 2001 From: Ashish Mhetre Date: Tue, 20 Feb 2024 04:12:26 +0000 Subject: [PATCH] video: tegra: nvmap: Take refcount on device during map When a dma_buf is getting mapped, take refcount on that device which will is released when dma_buf is unmapped. The device should be alive till all its buffers are unmapped. Bug 4402923 Change-Id: I3ad257f5bdd7e705ac94bea6e81fef0fda46fbd2 Signed-off-by: Ashish Mhetre Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/3079901 Tested-by: mobile promotions Reviewed-by: mobile promotions --- drivers/video/tegra/nvmap/nvmap_dmabuf.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/video/tegra/nvmap/nvmap_dmabuf.c b/drivers/video/tegra/nvmap/nvmap_dmabuf.c index ff07b51f..5260c9b4 100644 --- a/drivers/video/tegra/nvmap/nvmap_dmabuf.c +++ b/drivers/video/tegra/nvmap/nvmap_dmabuf.c @@ -180,8 +180,10 @@ static struct sg_table *nvmap_dmabuf_map_dma_buf(struct dma_buf_attachment *atta if (sgt) goto cache_hit; + get_device(attach->dev); sgt = __nvmap_sg_table(NULL, info->handle); if (IS_ERR(sgt)) { + put_device(attach->dev); atomic_dec(&info->handle->pin); mutex_unlock(&info->maps_lock); return sgt; @@ -224,6 +226,7 @@ cache_hit: err_map: __nvmap_free_sg_table(NULL, info->handle, sgt); + put_device(attach->dev); atomic_dec(&info->handle->pin); mutex_unlock(&info->maps_lock); return ERR_PTR(-ENOMEM); @@ -247,6 +250,7 @@ static void __nvmap_dmabuf_unmap_dma_buf(struct nvmap_handle_sgt *nvmap_sgt) dir, DMA_ATTR_SKIP_CPU_SYNC); } __nvmap_free_sg_table(NULL, info->handle, sgt); + put_device(dev); } static void nvmap_dmabuf_unmap_dma_buf(struct dma_buf_attachment *attach,