diff --git a/drivers/video/tegra/nvmap/nvmap_heap.c b/drivers/video/tegra/nvmap/nvmap_heap.c index 8fcdf433..f8899b1e 100644 --- a/drivers/video/tegra/nvmap/nvmap_heap.c +++ b/drivers/video/tegra/nvmap/nvmap_heap.c @@ -3,7 +3,7 @@ * * GPU heap allocator. * - * Copyright (c) 2011-2022, NVIDIA Corporation. All rights reserved. + * Copyright (c) 2011-2023, NVIDIA Corporation. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -535,6 +535,8 @@ struct nvmap_heap *nvmap_heap_create(struct device *parent, co->name, (void *)(uintptr_t)base, len/1024); return h; fail: + if (h->dma_dev->kobj.name) + kfree_const(h->dma_dev->kobj.name); kfree(h); return NULL; } @@ -543,6 +545,17 @@ fail: void nvmap_heap_destroy(struct nvmap_heap *heap) { WARN_ON(!list_empty(&heap->all_list)); + if (heap->dma_dev->kobj.name) + kfree_const(heap->dma_dev->kobj.name); + + if (heap->is_ivm) + kfree(heap->name); + +#ifdef NVMAP_LOADABLE_MODULE + nvmap_dma_release_coherent_memory((struct dma_coherent_mem_replica *) + heap->dma_dev->dma_mem); +#endif /* NVMAP_LOADABLE_MODULE */ + while (!list_empty(&heap->all_list)) { struct list_block *l; l = list_first_entry(&heap->all_list, struct list_block, diff --git a/drivers/video/tegra/nvmap/nvmap_init.c b/drivers/video/tegra/nvmap/nvmap_init.c index a54537dd..9a009665 100644 --- a/drivers/video/tegra/nvmap/nvmap_init.c +++ b/drivers/video/tegra/nvmap/nvmap_init.c @@ -576,7 +576,7 @@ void nvmap_dma_mark_declared_memory_unoccupied(struct device *dev, spin_unlock_irqrestore(&mem->spinlock, flags); } -static void nvmap_dma_release_coherent_memory(struct dma_coherent_mem_replica *mem) +void nvmap_dma_release_coherent_memory(struct dma_coherent_mem_replica *mem) { if (!mem) return; @@ -727,15 +727,9 @@ static int __init nvmap_co_device_init(struct reserved_mem *rmem, return err; } -static void nvmap_co_device_release(struct reserved_mem *rmem,struct device *dev) +static void nvmap_co_device_release(struct reserved_mem *rmem, struct device *dev) { - struct nvmap_platform_carveout *co = rmem->priv; - - if (!co) - return; - - if (co->usage_mask == NVMAP_HEAP_CARVEOUT_IVM) - kfree(co->name); + return; } static const struct reserved_mem_ops nvmap_co_ops = { diff --git a/drivers/video/tegra/nvmap/nvmap_priv.h b/drivers/video/tegra/nvmap/nvmap_priv.h index 17e65855..a7ba6e79 100644 --- a/drivers/video/tegra/nvmap/nvmap_priv.h +++ b/drivers/video/tegra/nvmap/nvmap_priv.h @@ -3,7 +3,7 @@ * * GPU memory management driver for Tegra * - * Copyright (c) 2009-2022, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2009-2023, NVIDIA CORPORATION. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -926,4 +926,8 @@ extern void __dma_map_area(const void *cpu_va, size_t size, int dir); int nvmap_assign_pages_to_handle(struct nvmap_client *client, struct nvmap_handle **hs, struct nvmap_handle *h, struct handles_range *rng); + +#ifdef NVMAP_LOADABLE_MODULE +void nvmap_dma_release_coherent_memory(struct dma_coherent_mem_replica *mem); +#endif /* NVMAP_LOADABLE_MODULE */ #endif /* __VIDEO_TEGRA_NVMAP_NVMAP_H */