diff mbox series

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

Message ID 20230706134000.130098-1-suijingfeng@loongson.cn (mailing list archive)
State New, archived
Headers show
Series [v2] drm/mediatek: Fix potential memory leak if vmap() fail | expand

Commit Message

Sui Jingfeng July 6, 2023, 1:40 p.m. UTC
Also return -ENOMEM if such a failure happens, the implement should take
responsibility for the error handling.

Fixes: 3df64d7b0a4f ("drm/mediatek: Implement gem prime vmap/vunmap function")
Reviewed-by: Matthias Brugger <matthias.bgg@gmail.com>
Reviewed-by: Alexandre Mergnat <amergnat@baylibre.com>
Signed-off-by: Sui Jingfeng <suijingfeng@loongson.cn>
---
 drivers/gpu/drm/mediatek/mtk_drm_gem.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

CK Hu (胡俊光) July 27, 2023, 1:47 a.m. UTC | #1
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@mediatek.com>

> 
> Fixes: 3df64d7b0a4f ("drm/mediatek: Implement gem prime vmap/vunmap
> function")
> Reviewed-by: Matthias Brugger <matthias.bgg@gmail.com>
> Reviewed-by: Alexandre Mergnat <amergnat@baylibre.com>
> Signed-off-by: Sui Jingfeng <suijingfeng@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
Sui Jingfeng July 27, 2023, 7:24 a.m. UTC | #2
Hi,


Thanks a lot!


On 2023/7/27 09:47, CK Hu (胡俊光) wrote:
> 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@mediatek.com>
>
> > 
> > Fixes: 3df64d7b0a4f ("drm/mediatek: Implement gem prime vmap/vunmap
> > function")
> > Reviewed-by: Matthias Brugger <matthias.bgg@gmail.com>
> > Reviewed-by: Alexandre Mergnat <amergnat@baylibre.com>
> > Signed-off-by: Sui Jingfeng <suijingfeng@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
>
> ************* MEDIATEK Confidentiality Notice ********************
> The information contained in this e-mail message (including any
> attachments) may be confidential, proprietary, privileged, or otherwise
> exempt from disclosure under applicable laws. It is intended to be
> conveyed only to the designated recipient(s). Any use, dissemination,
> distribution, printing, retaining or copying of this e-mail (including its
> attachments) by unintended recipient(s) is strictly prohibited and may
> be unlawful. If you are not an intended recipient of this e-mail, or believe
> that you have received this e-mail in error, please notify the sender
> immediately (by replying to this e-mail), delete any and all copies of
> this e-mail (including any attachments) from your system, and do not
> disclose the content of this e-mail to any other person. Thank you!
AngeloGioacchino Del Regno July 27, 2023, 9:22 a.m. UTC | #3
Il 06/07/23 15:40, Sui Jingfeng ha scritto:
> Also return -ENOMEM if such a failure happens, the implement should take
> responsibility for the error handling.
> 
> Fixes: 3df64d7b0a4f ("drm/mediatek: Implement gem prime vmap/vunmap function")
> Reviewed-by: Matthias Brugger <matthias.bgg@gmail.com>
> Reviewed-by: Alexandre Mergnat <amergnat@baylibre.com>
> Signed-off-by: Sui Jingfeng <suijingfeng@loongson.cn>

Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Sui Jingfeng July 27, 2023, 9:56 a.m. UTC | #4
Hi,

On 2023/7/27 17:22, AngeloGioacchino Del Regno wrote:
> Il 06/07/23 15:40, Sui Jingfeng ha scritto:
>> Also return -ENOMEM if such a failure happens, the implement should take
>> responsibility for the error handling.
>>
>> Fixes: 3df64d7b0a4f ("drm/mediatek: Implement gem prime vmap/vunmap 
>> function")
>> Reviewed-by: Matthias Brugger <matthias.bgg@gmail.com>
>> Reviewed-by: Alexandre Mergnat <amergnat@baylibre.com>
>> Signed-off-by: Sui Jingfeng <suijingfeng@loongson.cn>
>
> Reviewed-by: AngeloGioacchino Del Regno 
> <angelogioacchino.delregno@collabora.com>

Yeah! I got so many R-B!

So surprise, So happy!

Hopefully someone will merge/apply this patch someday, thanks.
diff mbox series

Patch

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);