dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] drm/mediatek: Fix potential memory leak if vmap() fail
@ 2023-07-06 13:40 Sui Jingfeng
  2023-07-27  1:47 ` CK Hu (胡俊光)
  2023-07-27  9:22 ` AngeloGioacchino Del Regno
  0 siblings, 2 replies; 5+ messages in thread
From: Sui Jingfeng @ 2023-07-06 13:40 UTC (permalink / raw)
  To: Chun-Kuang Hu, Philipp Zabel, David Airlie, Daniel Vetter,
	Matthias Brugger, AngeloGioacchino Del Regno, CK Hu
  Cc: Alexandre Mergnat, linux-mediatek, linux-arm-kernel, dri-devel,
	linux-kernel

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

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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] drm/mediatek: Fix potential memory leak if vmap() fail
  2023-07-06 13:40 [PATCH v2] drm/mediatek: Fix potential memory leak if vmap() fail Sui Jingfeng
@ 2023-07-27  1:47 ` CK Hu (胡俊光)
  2023-07-27  7:24   ` suijingfeng
  2023-07-27  9:22 ` AngeloGioacchino Del Regno
  1 sibling, 1 reply; 5+ messages in thread
From: CK Hu (胡俊光) @ 2023-07-27  1:47 UTC (permalink / raw)
  To: p.zabel, airlied, matthias.bgg, daniel, suijingfeng,
	chunkuang.hu, angelogioacchino.delregno
  Cc: amergnat, linux-mediatek, linux-arm-kernel, dri-devel, linux-kernel

[-- Attachment #1: Type: text/html, Size: 3055 bytes --]

[-- Attachment #2: Type: text/plain, Size: 1403 bytes --]

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] drm/mediatek: Fix potential memory leak if vmap() fail
  2023-07-27  1:47 ` CK Hu (胡俊光)
@ 2023-07-27  7:24   ` suijingfeng
  0 siblings, 0 replies; 5+ messages in thread
From: suijingfeng @ 2023-07-27  7:24 UTC (permalink / raw)
  To: CK Hu (胡俊光),
	p.zabel, airlied, matthias.bgg, daniel, chunkuang.hu,
	angelogioacchino.delregno
  Cc: amergnat, linux-kernel, dri-devel, loongson-kernel,
	linux-mediatek, linux-arm-kernel

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!


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] drm/mediatek: Fix potential memory leak if vmap() fail
  2023-07-06 13:40 [PATCH v2] drm/mediatek: Fix potential memory leak if vmap() fail Sui Jingfeng
  2023-07-27  1:47 ` CK Hu (胡俊光)
@ 2023-07-27  9:22 ` AngeloGioacchino Del Regno
  2023-07-27  9:56   ` suijingfeng
  1 sibling, 1 reply; 5+ messages in thread
From: AngeloGioacchino Del Regno @ 2023-07-27  9:22 UTC (permalink / raw)
  To: Sui Jingfeng, Chun-Kuang Hu, Philipp Zabel, David Airlie,
	Daniel Vetter, Matthias Brugger, CK Hu
  Cc: Alexandre Mergnat, linux-mediatek, linux-arm-kernel, dri-devel,
	linux-kernel

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>



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] drm/mediatek: Fix potential memory leak if vmap() fail
  2023-07-27  9:22 ` AngeloGioacchino Del Regno
@ 2023-07-27  9:56   ` suijingfeng
  0 siblings, 0 replies; 5+ messages in thread
From: suijingfeng @ 2023-07-27  9:56 UTC (permalink / raw)
  To: AngeloGioacchino Del Regno, Chun-Kuang Hu, Philipp Zabel,
	David Airlie, Daniel Vetter, Matthias Brugger, CK Hu,
	Thomas Zimmermann, Maxime Ripard
  Cc: Alexandre Mergnat, linux-kernel, dri-devel, loongson-kernel,
	linux-mediatek, linux-arm-kernel

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.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-07-27  9:56 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-06 13:40 [PATCH v2] drm/mediatek: Fix potential memory leak if vmap() fail Sui Jingfeng
2023-07-27  1:47 ` CK Hu (胡俊光)
2023-07-27  7:24   ` suijingfeng
2023-07-27  9:22 ` AngeloGioacchino Del Regno
2023-07-27  9:56   ` suijingfeng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).