mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Icenowy Zheng <zhengxingda@iscas.ac.cn>
To: Xi Ruoyao <xry111@xry111.site>,
	yaolu@kylinos.cn, lvjianmin@loongson.cn, wuqianhai@loongson.cn
Cc: chenhuacai@kernel.org, jeffbai@aosc.io,
	dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org
Subject: Re: [PATH] drm/loongson: add cleanup path for lsdc_ttm_init
Date: Tue, 19 May 2026 15:51:42 +0800	[thread overview]
Message-ID: <18e182e92a41459da5e7be0e43e62048ff2eba52.camel@iscas.ac.cn> (raw)
In-Reply-To: <580c761b3297a079b88823ce323c131b57696e71.camel@xry111.site>

在 2026-05-19二的 15:43 +0800,Xi Ruoyao写道:
> On Tue, 2026-05-19 at 15:41 +0800, yaolu@kylinos.cn wrote:
> > From: Lu Yao <yaolu@kylinos.cn>
> > 
> > There has resource leak when TTM_PL_VRAM or TTM_PL_TT man range
> > init
> > failed.
> > 
> > Signed-off-by: Lu Yao <yaolu@kylinos.cn>
> > ---
> >  drivers/gpu/drm/loongson/lsdc_ttm.c | 10 ++++++++--
> >  1 file changed, 8 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/loongson/lsdc_ttm.c
> > b/drivers/gpu/drm/loongson/lsdc_ttm.c
> > index d7441d96a0dc..c84bc582f77c 100644
> > --- a/drivers/gpu/drm/loongson/lsdc_ttm.c
> > +++ b/drivers/gpu/drm/loongson/lsdc_ttm.c
> > @@ -554,7 +554,7 @@ int lsdc_ttm_init(struct lsdc_device *ldev)
> >  
> >  	ret = ttm_range_man_init(&ldev->bdev, TTM_PL_VRAM, false,
> > num_vram_pages);
> >  	if (unlikely(ret))
> > -		return ret;
> > +		goto err_vram;
> >  
> >  	drm_info(ddev, "VRAM: %lu pages ready\n", num_vram_pages);
> >  
> > @@ -565,11 +565,17 @@ int lsdc_ttm_init(struct lsdc_device *ldev)
> >  
> >  	ret = ttm_range_man_init(&ldev->bdev, TTM_PL_TT, true,
> > num_gtt_pages);
> >  	if (unlikely(ret))
> > -		return ret;
> > +		goto err_gtt;
> >  
> >  	drm_info(ddev, "GTT: %lu pages ready\n", num_gtt_pages);
> >  
> >  	return drmm_add_action_or_reset(ddev, lsdc_ttm_fini,
> > ldev);
> 
> Isn't the error handling path also needed in case
> drmm_add_action_or_reset fails?

drmm_add_action_or_reset adds an action for teardown, and if it fails,
the teardown will immediately happen (this is what `or_reset` means).

The `lsdc_ttm_fini()` function will properly finalize both ttm range
managers and the ttm device, so it's not a problem here.

This patch is quite valid for handling the situation that some init
operations succeeded and some failed in this function.

Thanks,
Icenowy

> 
> > +
> > +err_gtt:
> > +	ttm_range_man_fini(&ldev->bdev, TTM_PL_VRAM);
> > +err_vram:
> > +	ttm_device_fini(&ldev->bdev);
> > +	return ret;
> >  }
> >  
> >  void lsdc_ttm_debugfs_init(struct lsdc_device *ldev)


      reply	other threads:[~2026-05-19  7:51 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-19  7:41 yaolu
2026-05-19  7:43 ` Xi Ruoyao
2026-05-19  7:51   ` Icenowy Zheng [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=18e182e92a41459da5e7be0e43e62048ff2eba52.camel@iscas.ac.cn \
    --to=zhengxingda@iscas.ac.cn \
    --cc=chenhuacai@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jeffbai@aosc.io \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lvjianmin@loongson.cn \
    --cc=wuqianhai@loongson.cn \
    --cc=xry111@xry111.site \
    --cc=yaolu@kylinos.cn \
    /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®