All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/nouveau/nouveau_bo: fix potential memory leak in nouveau_bo_alloc()
@ 2022-07-05  9:43 ` Jianglei Nie
  0 siblings, 0 replies; 4+ messages in thread
From: Jianglei Nie @ 2022-07-05  9:43 UTC (permalink / raw)
  To: bskeggs, kherbst, lyude, airlied, daniel
  Cc: ri-devel, nouveau, linux-kernel, Jianglei Nie

nouveau_bo_alloc() allocates a memory chunk for "nvbo" with kzalloc().
When some error occurs, "nvbo" should be released. But when
WARN_ON(pi < 0)) equals true, the function return ERR_PTR without
releasing the "nvbo", which will lead to a memory leak.

We should release the "nvbo" with kfree() if WARN_ON(pi < 0)) equals true.

Signed-off-by: Jianglei Nie <niejianglei2021@163.com>
---
 drivers/gpu/drm/nouveau/nouveau_bo.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau/nouveau_bo.c
index 05076e530e7d..d0887438b07e 100644
--- a/drivers/gpu/drm/nouveau/nouveau_bo.c
+++ b/drivers/gpu/drm/nouveau/nouveau_bo.c
@@ -281,8 +281,10 @@ nouveau_bo_alloc(struct nouveau_cli *cli, u64 *size, int *align, u32 domain,
 			break;
 	}
 
-	if (WARN_ON(pi < 0))
+	if (WARN_ON(pi < 0)) {
+		kfree(nvbo);
 		return ERR_PTR(-EINVAL);
+	}
 
 	/* Disable compression if suitable settings couldn't be found. */
 	if (nvbo->comp && !vmm->page[pi].comp) {
-- 
2.25.1


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

* [Nouveau] [PATCH] drm/nouveau/nouveau_bo: fix potential memory leak in nouveau_bo_alloc()
@ 2022-07-05  9:43 ` Jianglei Nie
  0 siblings, 0 replies; 4+ messages in thread
From: Jianglei Nie @ 2022-07-05  9:43 UTC (permalink / raw)
  To: bskeggs, kherbst, lyude, airlied, daniel
  Cc: nouveau, ri-devel, linux-kernel, Jianglei Nie

nouveau_bo_alloc() allocates a memory chunk for "nvbo" with kzalloc().
When some error occurs, "nvbo" should be released. But when
WARN_ON(pi < 0)) equals true, the function return ERR_PTR without
releasing the "nvbo", which will lead to a memory leak.

We should release the "nvbo" with kfree() if WARN_ON(pi < 0)) equals true.

Signed-off-by: Jianglei Nie <niejianglei2021@163.com>
---
 drivers/gpu/drm/nouveau/nouveau_bo.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau/nouveau_bo.c
index 05076e530e7d..d0887438b07e 100644
--- a/drivers/gpu/drm/nouveau/nouveau_bo.c
+++ b/drivers/gpu/drm/nouveau/nouveau_bo.c
@@ -281,8 +281,10 @@ nouveau_bo_alloc(struct nouveau_cli *cli, u64 *size, int *align, u32 domain,
 			break;
 	}
 
-	if (WARN_ON(pi < 0))
+	if (WARN_ON(pi < 0)) {
+		kfree(nvbo);
 		return ERR_PTR(-EINVAL);
+	}
 
 	/* Disable compression if suitable settings couldn't be found. */
 	if (nvbo->comp && !vmm->page[pi].comp) {
-- 
2.25.1


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

* Re: [PATCH] drm/nouveau/nouveau_bo: fix potential memory leak in nouveau_bo_alloc()
  2022-07-05  9:43 ` [Nouveau] " Jianglei Nie
@ 2022-07-07 19:55   ` Lyude Paul
  -1 siblings, 0 replies; 4+ messages in thread
From: Lyude Paul @ 2022-07-07 19:55 UTC (permalink / raw)
  To: Jianglei Nie, bskeggs, kherbst, airlied, daniel
  Cc: ri-devel, nouveau, linux-kernel

Reviewed-by: Lyude Paul <lyude@redhat.com>

Will push

On Tue, 2022-07-05 at 17:43 +0800, Jianglei Nie wrote:
> nouveau_bo_alloc() allocates a memory chunk for "nvbo" with kzalloc().
> When some error occurs, "nvbo" should be released. But when
> WARN_ON(pi < 0)) equals true, the function return ERR_PTR without
> releasing the "nvbo", which will lead to a memory leak.
> 
> We should release the "nvbo" with kfree() if WARN_ON(pi < 0)) equals true.
> 
> Signed-off-by: Jianglei Nie <niejianglei2021@163.com>
> ---
>  drivers/gpu/drm/nouveau/nouveau_bo.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c
> b/drivers/gpu/drm/nouveau/nouveau_bo.c
> index 05076e530e7d..d0887438b07e 100644
> --- a/drivers/gpu/drm/nouveau/nouveau_bo.c
> +++ b/drivers/gpu/drm/nouveau/nouveau_bo.c
> @@ -281,8 +281,10 @@ nouveau_bo_alloc(struct nouveau_cli *cli, u64 *size,
> int *align, u32 domain,
>                         break;
>         }
>  
> -       if (WARN_ON(pi < 0))
> +       if (WARN_ON(pi < 0)) {
> +               kfree(nvbo);
>                 return ERR_PTR(-EINVAL);
> +       }
>  
>         /* Disable compression if suitable settings couldn't be found. */
>         if (nvbo->comp && !vmm->page[pi].comp) {

-- 
Cheers,
 Lyude Paul (she/her)
 Software Engineer at Red Hat


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

* Re: [Nouveau] [PATCH] drm/nouveau/nouveau_bo: fix potential memory leak in nouveau_bo_alloc()
@ 2022-07-07 19:55   ` Lyude Paul
  0 siblings, 0 replies; 4+ messages in thread
From: Lyude Paul @ 2022-07-07 19:55 UTC (permalink / raw)
  To: Jianglei Nie, bskeggs, kherbst, airlied, daniel
  Cc: nouveau, ri-devel, linux-kernel

Reviewed-by: Lyude Paul <lyude@redhat.com>

Will push

On Tue, 2022-07-05 at 17:43 +0800, Jianglei Nie wrote:
> nouveau_bo_alloc() allocates a memory chunk for "nvbo" with kzalloc().
> When some error occurs, "nvbo" should be released. But when
> WARN_ON(pi < 0)) equals true, the function return ERR_PTR without
> releasing the "nvbo", which will lead to a memory leak.
> 
> We should release the "nvbo" with kfree() if WARN_ON(pi < 0)) equals true.
> 
> Signed-off-by: Jianglei Nie <niejianglei2021@163.com>
> ---
>  drivers/gpu/drm/nouveau/nouveau_bo.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c
> b/drivers/gpu/drm/nouveau/nouveau_bo.c
> index 05076e530e7d..d0887438b07e 100644
> --- a/drivers/gpu/drm/nouveau/nouveau_bo.c
> +++ b/drivers/gpu/drm/nouveau/nouveau_bo.c
> @@ -281,8 +281,10 @@ nouveau_bo_alloc(struct nouveau_cli *cli, u64 *size,
> int *align, u32 domain,
>                         break;
>         }
>  
> -       if (WARN_ON(pi < 0))
> +       if (WARN_ON(pi < 0)) {
> +               kfree(nvbo);
>                 return ERR_PTR(-EINVAL);
> +       }
>  
>         /* Disable compression if suitable settings couldn't be found. */
>         if (nvbo->comp && !vmm->page[pi].comp) {

-- 
Cheers,
 Lyude Paul (she/her)
 Software Engineer at Red Hat


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

end of thread, other threads:[~2022-08-04 20:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-05  9:43 [PATCH] drm/nouveau/nouveau_bo: fix potential memory leak in nouveau_bo_alloc() Jianglei Nie
2022-07-05  9:43 ` [Nouveau] " Jianglei Nie
2022-07-07 19:55 ` Lyude Paul
2022-07-07 19:55   ` [Nouveau] " Lyude Paul

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.