[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAKGbVbsp0Bhk3h3D4bkmpLT7HF6KykTJCUcb_JDL=UtJNc-h5A@mail.gmail.com>
Date: Fri, 19 Jan 2024 10:47:21 +0800
From: Qiang Yu <yuq825@...il.com>
To: Zhipeng Lu <alexious@....edu.cn>
Cc: Maarten Lankhorst <maarten.lankhorst@...ux.intel.com>, Maxime Ripard <mripard@...nel.org>,
Thomas Zimmermann <tzimmermann@...e.de>, David Airlie <airlied@...il.com>, Daniel Vetter <daniel@...ll.ch>,
Vasily Khoruzhick <anarsoul@...il.com>, dri-devel@...ts.freedesktop.org,
lima@...ts.freedesktop.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] [v2] drm/lima: fix a memleak in lima_heap_alloc
applied to drm-misc-next
On Wed, Jan 17, 2024 at 8:14 PM Qiang Yu <yuq825@...il.com> wrote:
>
> Reviewed-by: Qiang Yu <yuq825@...il.com>
>
> On Wed, Jan 17, 2024 at 3:14 PM Zhipeng Lu <alexious@....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@....edu.cn>
> > ---
> > Changelog:
> >
> > v2: rearrange the error-handling to ladder tags.
> > ---
> > drivers/gpu/drm/lima/lima_gem.c | 23 +++++++++++++++--------
> > 1 file changed, 15 insertions(+), 8 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/lima/lima_gem.c b/drivers/gpu/drm/lima/lima_gem.c
> > index 4f9736e5f929..d3d82ee7fb4c 100644
> > --- a/drivers/gpu/drm/lima/lima_gem.c
> > +++ b/drivers/gpu/drm/lima/lima_gem.c
> > @@ -75,29 +75,36 @@ int lima_heap_alloc(struct lima_bo *bo, struct lima_vm *vm)
> > } else {
> > bo->base.sgt = kmalloc(sizeof(*bo->base.sgt), GFP_KERNEL);
> > if (!bo->base.sgt) {
> > - sg_free_table(&sgt);
> > - return -ENOMEM;
> > + ret = -ENOMEM;
> > + goto err_out0;
> > }
> > }
> >
> > ret = dma_map_sgtable(dev, &sgt, DMA_BIDIRECTIONAL, 0);
> > if (ret) {
> > - sg_free_table(&sgt);
> > - kfree(bo->base.sgt);
> > - bo->base.sgt = NULL;
> > - return ret;
> > + goto err_out1;
> > }
> >
> > *bo->base.sgt = sgt;
> >
> > if (vm) {
> > ret = lima_vm_map_bo(vm, bo, old_size >> PAGE_SHIFT);
> > - if (ret)
> > - return ret;
> > + if (ret) {
> > + goto err_out2;
> > + }
> > }
> >
> > bo->heap_size = new_size;
> > return 0;
> > +
> > +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;
> > }
> >
> > int lima_gem_create_handle(struct drm_device *dev, struct drm_file *file,
> > --
> > 2.34.1
> >
Powered by blists - more mailing lists