mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: alexious@zju.edu.cn
To: "Qiang Yu" <yuq825@gmail.com>
Cc: "Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
	"Maxime Ripard" <mripard@kernel.org>,
	"Thomas Zimmermann" <tzimmermann@suse.de>,
	"David Airlie" <airlied@gmail.com>,
	"Daniel Vetter" <daniel@ffwll.ch>,
	"Vasily Khoruzhick" <anarsoul@gmail.com>,
	dri-devel@lists.freedesktop.org, lima@lists.freedesktop.org,
	linux-kernel@vger.kernel.org
Subject: Re: Re: [PATCH] drm/lima: fix a memleak in lima_heap_alloc
Date: Wed, 17 Jan 2024 15:10:19 +0800 (GMT+08:00)	[thread overview]
Message-ID: <397c98b.49eb.18d1641ad63.Coremail.alexious@zju.edu.cn> (raw)
In-Reply-To: <CAKGbVbswTUYJsZDLWao58MTyt7yAYMMXA5zjeYVBTRvd9X3n0g@mail.gmail.com>

> Thanks for the fix. As the error handling gets longer and duplicated,
> could you rearrange them like the lima_gem_submit():
> err_out2:
>     dma_unmap_sgtable(dev, &sgt, DMA_BIDIRECTIONAL, 0);
> err_out1:
>     kfree(bo->base.sgt);
>     bo->base.sgt = NULL;
> err_out0:
>     sg_free_table(&sgt);
>     return ret.
> 
> Regards,
> Qiang
> 

Sure, I'll send a v2 version of this patch later following your advise.

Regards,
Zhipeng

> On Fri, Jan 12, 2024 at 4:49 PM Zhipeng Lu <alexious@zju.edu.cn> wrote:
> >
> > When lima_vm_map_bo fails, the resources need to be deallocated, or
> > there will be memleaks.
> >
> > Fixes: 6aebc51d7aef ("drm/lima: support heap buffer creation")
> > Signed-off-by: Zhipeng Lu <alexious@zju.edu.cn>
> > ---
> >  drivers/gpu/drm/lima/lima_gem.c | 7 ++++++-
> >  1 file changed, 6 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/gpu/drm/lima/lima_gem.c b/drivers/gpu/drm/lima/lima_gem.c
> > index 4f9736e5f929..824ed22141c7 100644
> > --- a/drivers/gpu/drm/lima/lima_gem.c
> > +++ b/drivers/gpu/drm/lima/lima_gem.c
> > @@ -92,8 +92,13 @@ int lima_heap_alloc(struct lima_bo *bo, struct lima_vm *vm)
> >
> >         if (vm) {
> >                 ret = lima_vm_map_bo(vm, bo, old_size >> PAGE_SHIFT);
> > -               if (ret)
> > +               if (ret) {
> > +                       dma_unmap_sgtable(dev, &sgt, DMA_BIDIRECTIONAL, 0);
> > +                       sg_free_table(&sgt);
> > +                       kfree(bo->base.sgt);
> > +                       bo->base.sgt = NULL;
> >                         return ret;
> > +               }
> >         }
> >
> >         bo->heap_size = new_size;
> > --
> > 2.34.1
> >

      reply	other threads:[~2024-01-17  7:10 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-12  8:47 Zhipeng Lu
2024-01-16  1:24 ` Qiang Yu
2024-01-17  7:10   ` alexious [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=397c98b.49eb.18d1641ad63.Coremail.alexious@zju.edu.cn \
    --to=alexious@zju.edu.cn \
    --cc=airlied@gmail.com \
    --cc=anarsoul@gmail.com \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=lima@lists.freedesktop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=tzimmermann@suse.de \
    --cc=yuq825@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®