linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm/nouveau: Fix memory leak in nouveau_bo_alloc
@ 2019-10-21 21:14 Navid Emamdoost
  2019-10-22  9:40 ` Markus Elfring
  2019-11-21 18:09 ` Navid Emamdoost
  0 siblings, 2 replies; 5+ messages in thread
From: Navid Emamdoost @ 2019-10-21 21:14 UTC (permalink / raw)
  Cc: emamd001, kjlu, smccaman, Navid Emamdoost, Ben Skeggs,
	David Airlie, Daniel Vetter, dri-devel, nouveau, linux-kernel

In the implementation of nouveau_bo_alloc() if it fails to determine the
target page size via pi, then the allocated memory for nvbo should be
released.

Fixes: 019cbd4a4feb ("drm/nouveau: Initialize GEM object before TTM object")
Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.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 f8015e0318d7..18857cf44068 100644
--- a/drivers/gpu/drm/nouveau/nouveau_bo.c
+++ b/drivers/gpu/drm/nouveau/nouveau_bo.c
@@ -276,8 +276,10 @@ nouveau_bo_alloc(struct nouveau_cli *cli, u64 *size, int *align, u32 flags,
 			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.17.1


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

* Re: [PATCH] drm/nouveau: Fix memory leak in nouveau_bo_alloc
  2019-10-21 21:14 [PATCH] drm/nouveau: Fix memory leak in nouveau_bo_alloc Navid Emamdoost
@ 2019-10-22  9:40 ` Markus Elfring
  2019-11-21 18:09 ` Navid Emamdoost
  1 sibling, 0 replies; 5+ messages in thread
From: Markus Elfring @ 2019-10-22  9:40 UTC (permalink / raw)
  To: Navid Emamdoost, Thierry Reding, Gerd Hoffmann, Ben Skeggs,
	nouveau, dri-devel
  Cc: LKML, kernel-janitors, Navid Emamdoost, Kangjie Lu,
	Stephen McCamant, Daniel Vetter, David Airlie

> +++ b/drivers/gpu/drm/nouveau/nouveau_bo.c
> @@ -276,8 +276,10 @@ nouveau_bo_alloc(struct nouveau_cli *cli, u64 *size, int *align, u32 flags,
>  			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) {

This addition looks correct.
But I would prefer to move such exception handling code to the end of
this function implementation so that duplicate source code will be reduced.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-style.rst?id=7d194c2100ad2a6dded545887d02754948ca5241#n450

Regards,
Markus

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

* Re: [PATCH] drm/nouveau: Fix memory leak in nouveau_bo_alloc
  2019-10-21 21:14 [PATCH] drm/nouveau: Fix memory leak in nouveau_bo_alloc Navid Emamdoost
  2019-10-22  9:40 ` Markus Elfring
@ 2019-11-21 18:09 ` Navid Emamdoost
  2019-11-26 17:50   ` Navid Emamdoost
  1 sibling, 1 reply; 5+ messages in thread
From: Navid Emamdoost @ 2019-11-21 18:09 UTC (permalink / raw)
  To: David Airlie, Daniel Vetter, dri-devel, nouveau, Ben Skeggs
  Cc: Navid Emamdoost, LKML

On Mon, Oct 21, 2019 at 4:14 PM Navid Emamdoost
<navid.emamdoost@gmail.com> wrote:
>
> In the implementation of nouveau_bo_alloc() if it fails to determine the
> target page size via pi, then the allocated memory for nvbo should be
> released.
>
> Fixes: 019cbd4a4feb ("drm/nouveau: Initialize GEM object before TTM object")
> Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>

Would you please review this patch?


Thanks,
Navid.

> ---
>  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 f8015e0318d7..18857cf44068 100644
> --- a/drivers/gpu/drm/nouveau/nouveau_bo.c
> +++ b/drivers/gpu/drm/nouveau/nouveau_bo.c
> @@ -276,8 +276,10 @@ nouveau_bo_alloc(struct nouveau_cli *cli, u64 *size, int *align, u32 flags,
>                         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.17.1
>


-- 
Navid.

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

* Re: [PATCH] drm/nouveau: Fix memory leak in nouveau_bo_alloc
  2019-11-21 18:09 ` Navid Emamdoost
@ 2019-11-26 17:50   ` Navid Emamdoost
  2019-12-11  2:32     ` Navid Emamdoost
  0 siblings, 1 reply; 5+ messages in thread
From: Navid Emamdoost @ 2019-11-26 17:50 UTC (permalink / raw)
  To: David Airlie, Daniel Vetter, dri-devel, nouveau, Ben Skeggs
  Cc: Navid Emamdoost, LKML

ping...

On Thu, Nov 21, 2019 at 12:09 PM Navid Emamdoost
<navid.emamdoost@gmail.com> wrote:
>
> On Mon, Oct 21, 2019 at 4:14 PM Navid Emamdoost
> <navid.emamdoost@gmail.com> wrote:
> >
> > In the implementation of nouveau_bo_alloc() if it fails to determine the
> > target page size via pi, then the allocated memory for nvbo should be
> > released.
> >
> > Fixes: 019cbd4a4feb ("drm/nouveau: Initialize GEM object before TTM object")
> > Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
>
> Would you please review this patch?
>
>
> Thanks,
> Navid.
>
> > ---
> >  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 f8015e0318d7..18857cf44068 100644
> > --- a/drivers/gpu/drm/nouveau/nouveau_bo.c
> > +++ b/drivers/gpu/drm/nouveau/nouveau_bo.c
> > @@ -276,8 +276,10 @@ nouveau_bo_alloc(struct nouveau_cli *cli, u64 *size, int *align, u32 flags,
> >                         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.17.1
> >
>
>
> --
> Navid.



-- 
Navid.

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

* Re: [PATCH] drm/nouveau: Fix memory leak in nouveau_bo_alloc
  2019-11-26 17:50   ` Navid Emamdoost
@ 2019-12-11  2:32     ` Navid Emamdoost
  0 siblings, 0 replies; 5+ messages in thread
From: Navid Emamdoost @ 2019-12-11  2:32 UTC (permalink / raw)
  To: David Airlie, Daniel Vetter, dri-devel, nouveau, Ben Skeggs
  Cc: Navid Emamdoost, LKML

ping ...

On Tue, Nov 26, 2019 at 11:50 AM Navid Emamdoost
<navid.emamdoost@gmail.com> wrote:
>
> ping...
>
> On Thu, Nov 21, 2019 at 12:09 PM Navid Emamdoost
> <navid.emamdoost@gmail.com> wrote:
> >
> > On Mon, Oct 21, 2019 at 4:14 PM Navid Emamdoost
> > <navid.emamdoost@gmail.com> wrote:
> > >
> > > In the implementation of nouveau_bo_alloc() if it fails to determine the
> > > target page size via pi, then the allocated memory for nvbo should be
> > > released.
> > >
> > > Fixes: 019cbd4a4feb ("drm/nouveau: Initialize GEM object before TTM object")
> > > Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
> >
> > Would you please review this patch?
> >
> >
> > Thanks,
> > Navid.
> >
> > > ---
> > >  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 f8015e0318d7..18857cf44068 100644
> > > --- a/drivers/gpu/drm/nouveau/nouveau_bo.c
> > > +++ b/drivers/gpu/drm/nouveau/nouveau_bo.c
> > > @@ -276,8 +276,10 @@ nouveau_bo_alloc(struct nouveau_cli *cli, u64 *size, int *align, u32 flags,
> > >                         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.17.1
> > >
> >
> >
> > --
> > Navid.
>
>
>
> --
> Navid.



-- 
Navid.

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

end of thread, other threads:[~2019-12-11  2:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-21 21:14 [PATCH] drm/nouveau: Fix memory leak in nouveau_bo_alloc Navid Emamdoost
2019-10-22  9:40 ` Markus Elfring
2019-11-21 18:09 ` Navid Emamdoost
2019-11-26 17:50   ` Navid Emamdoost
2019-12-11  2:32     ` Navid Emamdoost

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