mirror of
https://github.com/raspberrypi/linux.git
synced 2025-12-06 10:00:17 +00:00
drm/lima: fix a memleak in lima_heap_alloc
[ Upstream commit04ae3eb470] When lima_vm_map_bo fails, the resources need to be deallocated, or there will be memleaks. Fixes:6aebc51d7a("drm/lima: support heap buffer creation") Signed-off-by: Zhipeng Lu <alexious@zju.edu.cn> Signed-off-by: Qiang Yu <yuq825@gmail.com> Link: https://patchwork.freedesktop.org/patch/msgid/20240117071328.3811480-1-alexious@zju.edu.cn Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
@@ -75,29 +75,34 @@ int lima_heap_alloc(struct lima_bo *bo, struct lima_vm *vm)
|
|||||||
} else {
|
} else {
|
||||||
bo->base.sgt = kmalloc(sizeof(*bo->base.sgt), GFP_KERNEL);
|
bo->base.sgt = kmalloc(sizeof(*bo->base.sgt), GFP_KERNEL);
|
||||||
if (!bo->base.sgt) {
|
if (!bo->base.sgt) {
|
||||||
sg_free_table(&sgt);
|
ret = -ENOMEM;
|
||||||
return -ENOMEM;
|
goto err_out0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = dma_map_sgtable(dev, &sgt, DMA_BIDIRECTIONAL, 0);
|
ret = dma_map_sgtable(dev, &sgt, DMA_BIDIRECTIONAL, 0);
|
||||||
if (ret) {
|
if (ret)
|
||||||
sg_free_table(&sgt);
|
goto err_out1;
|
||||||
kfree(bo->base.sgt);
|
|
||||||
bo->base.sgt = NULL;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
*bo->base.sgt = sgt;
|
*bo->base.sgt = sgt;
|
||||||
|
|
||||||
if (vm) {
|
if (vm) {
|
||||||
ret = lima_vm_map_bo(vm, bo, old_size >> PAGE_SHIFT);
|
ret = lima_vm_map_bo(vm, bo, old_size >> PAGE_SHIFT);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
goto err_out2;
|
||||||
}
|
}
|
||||||
|
|
||||||
bo->heap_size = new_size;
|
bo->heap_size = new_size;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
err_out2:
|
||||||
|
dma_unmap_sgtable(dev, &sgt, DMA_BIDIRECTIONAL, 0);
|
||||||
|
err_out1:
|
||||||
|
kfree(bo->base.sgt);
|
||||||
|
bo->base.sgt = NULL;
|
||||||
|
err_out0:
|
||||||
|
sg_free_table(&sgt);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int lima_gem_create_handle(struct drm_device *dev, struct drm_file *file,
|
int lima_gem_create_handle(struct drm_device *dev, struct drm_file *file,
|
||||||
|
|||||||
Reference in New Issue
Block a user