mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Icenowy Zheng <zhengxingda@iscas.ac.cn>
To: Evanshenf <archwse@gmail.com>, dri-devel@lists.freedesktop.org
Cc: Jianmin Lv <lvjianmin@loongson.cn>,
	Qianhai Wu <wuqianhai@loongson.cn>,
	 Huacai Chen <chenhuacai@kernel.org>,
	Mingcong Bai <jeffbai@aosc.io>, Xi Ruoyao <xry111@xry111.site>,
	Sui Jingfeng <suijingfeng@loongson.cn>,
	stable@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] drm/loongson: Fix double free on BO initialization failure
Date: Fri, 09 Oct 2026 16:42:14 +0800	[thread overview]
Message-ID: <dce8506787ff72b5a9fac15571d4c59624348430.camel@iscas.ac.cn> (raw)
In-Reply-To: <20261003093415.e64386de1e64-1-archwse@gmail.com>

在 2026-10-03六的 09:34 +0000,Evanshenf写道:
> If ttm_bo_init_validate() fails, it drops the buffer object's
> reference
> and cleans it up through the supplied destroy callback.
> lsdc_bo_destroy()
> releases the GEM object and frees the enclosing lsdc_bo, so freeing
> it
> again in lsdc_bo_create() causes a double free on a synchronous
> failure
> path.
> 
> Let TTM own the cleanup after initialization has started and return
> the
> error directly. Keep the explicit free on drm_gem_object_init()
> failure,
> which occurs before ownership is passed to TTM.
> 
> Tested on LS7A2000 by making drm_vma_offset_add() return -ENOSPC for
> one
> selected dumb-buffer creation. The error reached userspace, the
> destroy
> callback ran once, and no handle was published or tracked BO
> retained.
> Normal buffer creation, zeroing, mapping, readback and release
> passed.
> 
> AI assistance was used for the ownership analysis, fix, fault-
> injection
> tools, build and test execution.
> 
> Fixes: f39db26c5428 ("drm: Add kms driver for loongson display
> controller")
> Cc: stable@vger.kernel.org
> Assisted-by: LLM
> Signed-off-by: Evanshenf <archwse@gmail.com>
> ---
>  drivers/gpu/drm/loongson/lsdc_ttm.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/loongson/lsdc_ttm.c
> b/drivers/gpu/drm/loongson/lsdc_ttm.c
> index d7441d9..88536e2 100644
> --- a/drivers/gpu/drm/loongson/lsdc_ttm.c
> +++ b/drivers/gpu/drm/loongson/lsdc_ttm.c
> @@ -475,10 +475,8 @@ struct lsdc_bo *lsdc_bo_create(struct drm_device
> *ddev,
>  
>  	ret = ttm_bo_init_validate(bdev, tbo, bo_type, &lbo-
> >placement, 0,
>  				   false, sg, resv,
> lsdc_bo_destroy);
> -	if (ret) {
> -		kfree(lbo);
> +	if (ret)
>  		return ERR_PTR(ret);

It looks like this fix is valid, ttm_bo_init_reserved() (called by
ttm_bo_init_validate() ) will do a ttm_bo_put() operation when failure,
which leads to calling the destroy callback.

```
Reviewed-by: Icenowy Zheng <zhengxingda@iscas.ac.cn>
```

Thanks,
Icenowy

> -	}
>  
>  	return lbo;
>  }
> 
> base-commit: bca45af5998a05f34b13a2ef11e639bac9c62643


  parent reply	other threads:[~2026-10-09  8:42 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-03  9:34 Evanshenf
2026-10-03  9:34 ` [PATCH 2/2] drm/loongson: Handle buffer mapping failures when clearing a BO Evanshenf
2026-10-09 13:50   ` Icenowy Zheng
2026-10-09 14:14     ` Christian König
2026-10-09 14:20       ` Icenowy Zheng
2026-10-10  6:38       ` Icenowy Zheng
2026-10-09  8:42 ` Icenowy Zheng [this message]
2026-10-09  9:37   ` [PATCH 1/2] drm/loongson: Fix double free on BO initialization failure wuqianhai
2026-10-11 14:03 ` Huacai Chen
2026-10-31  4:26 ` Icenowy Zheng

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=dce8506787ff72b5a9fac15571d4c59624348430.camel@iscas.ac.cn \
    --to=zhengxingda@iscas.ac.cn \
    --cc=archwse@gmail.com \
    --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=stable@vger.kernel.org \
    --cc=suijingfeng@loongson.cn \
    --cc=wuqianhai@loongson.cn \
    --cc=xry111@xry111.site \
    /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®