[PATCH v2] drm/mediatek: Fix potential memory leak if vmap() fail

CK Hu (胡俊光) ck.hu at mediatek.com
Wed Jul 26 18:47:31 PDT 2023


Hi, Jingfeng:

On Thu, 2023-07-06 at 21:40 +0800, Sui Jingfeng wrote:
>  	 
> External email : Please do not click links or open attachments until
> you have verified the sender or the content.
>  Also return -ENOMEM if such a failure happens, the implement should
> take
> responsibility for the error handling.

Reviewed-by: CK Hu <ck.hu at mediatek.com>

> 
> Fixes: 3df64d7b0a4f ("drm/mediatek: Implement gem prime vmap/vunmap
> function")
> Reviewed-by: Matthias Brugger <matthias.bgg at gmail.com>
> Reviewed-by: Alexandre Mergnat <amergnat at baylibre.com>
> Signed-off-by: Sui Jingfeng <suijingfeng at loongson.cn>
> ---
>  drivers/gpu/drm/mediatek/mtk_drm_gem.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/mediatek/mtk_drm_gem.c
> b/drivers/gpu/drm/mediatek/mtk_drm_gem.c
> index a25b28d3ee90..9f364df52478 100644
> --- a/drivers/gpu/drm/mediatek/mtk_drm_gem.c
> +++ b/drivers/gpu/drm/mediatek/mtk_drm_gem.c
> @@ -247,7 +247,11 @@ int mtk_drm_gem_prime_vmap(struct drm_gem_object
> *obj, struct iosys_map *map)
>  
>  	mtk_gem->kvaddr = vmap(mtk_gem->pages, npages, VM_MAP,
>  			       pgprot_writecombine(PAGE_KERNEL));
> -
> +	if (!mtk_gem->kvaddr) {
> +		kfree(sgt);
> +		kfree(mtk_gem->pages);
> +		return -ENOMEM;
> +	}
>  out:
>  	kfree(sgt);
>  	iosys_map_set_vaddr(map, mtk_gem->kvaddr);
> -- 
> 2.34.1


More information about the linux-arm-kernel mailing list