All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Christian König" <ckoenig.leichtzumerken@gmail.com>
Cc: intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
	intel-xe@lists.freedesktop.org
Subject: Re: [PATCH 04/10] drm/gem: Convert drm_gem_private_object_init to return error code
Date: Thu, 27 Aug 2026 13:19:14 +0000	[thread overview]
Message-ID: <20260827131915.40AC81F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260827124910.2245-5-christian.koenig@amd.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Medium] Memory leak in xe_bo_init_locked() on drm_gem_private_object_init() failure.
- [Medium] Memory leak in vmw_bo_create() when vmw_bo_init() fails at GEM initialization.
- [Medium] Heap allocation leak in amdxdna_drm_create_dev_bo() when drm_gem_private_object_init() fails.
--

commit 31f8fb9f49fa7d6352b54fca867dc5132c27a261
Author: Christian König <ckoenig.leichtzumerken@gmail.com>

drm/gem: Convert drm_gem_private_object_init to return error code

This commit changes drm_gem_private_object_init() to return an error code
instead of void, allowing it to gracefully fail rather than crashing the
kernel with BUG_ON. Call sites across various DRM and accelerator drivers
have been updated to check the return value and handle errors appropriately.

[ ... ]

> diff --git a/drivers/accel/amdxdna/amdxdna_gem.c b/drivers/accel/amdxdna/amdxdna_gem.c
> index b01f5d95fac83..96490aa0af1be 100644
> --- a/drivers/accel/amdxdna/amdxdna_gem.c
> +++ b/drivers/accel/amdxdna/amdxdna_gem.c
> @@ -1050,7 +1050,11 @@ amdxdna_drm_create_dev_bo(struct drm_device *dev,
>  		return ERR_PTR(ret);
>  	}
>  
> -	drm_gem_private_object_init(dev, gobj, aligned_sz);
> +	ret = drm_gem_private_object_init(dev, gobj, aligned_sz);
> +	if (ret) {
> +		amdxdna_gem_destroy_obj(abo);
> +		return ERR_PTR(ret);
> +	}

[Severity: Medium]
Does this code leak the heap allocation? In amdxdna_drm_create_dev_bo(), 
there is an earlier successful call to amdxdna_gem_heap_alloc(). If 
drm_gem_private_object_init() fails, the error handler only calls 
amdxdna_gem_destroy_obj() and skips calling amdxdna_gem_heap_free(), 
which leaves a persistent resource leak in the client's heap tracking.

[ ... ]

> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c
> index 9c7a73c0b0dc3..e4e4b87e738d3 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c
> @@ -426,7 +426,9 @@ static int vmw_bo_init(struct vmw_private *dev_priv,
>  	atomic_set(&vmw_bo->map_count, 0);
>  
>  	params->size = ALIGN(params->size, PAGE_SIZE);
> -	drm_gem_private_object_init(vdev, &vmw_bo->tbo.base, params->size);
> +	ret = drm_gem_private_object_init(vdev, &vmw_bo->tbo.base, params->size);
> +	if (ret)
> +		return ret;
>  
>  	vmw_bo_placement_set(vmw_bo, params->domain, params->busy_domain);
>  	ret = ttm_bo_init_reserved(bdev, &vmw_bo->tbo, params->bo_type,

[Severity: Medium]
Could this early return cause the vmw_bo structure to be leaked? 
When vmw_bo_create() allocates the object, it passes it to vmw_bo_init()
with a destruction callback. If drm_gem_private_object_init() fails and
returns early here, it bypasses the ttm_bo_init_reserved() setup. Because
TTM never receives the destruction callback, the caller receives the error 
and nullifies the pointer without actually freeing it, permanently leaking 
the struct.

[ ... ]

> diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
> index dde309821237b..85e49b48f9d3a 100644
> --- a/drivers/gpu/drm/xe/xe_bo.c
> +++ b/drivers/gpu/drm/xe/xe_bo.c
> @@ -2400,7 +2400,9 @@ struct xe_bo *xe_bo_init_locked(struct xe_device *xe, struct xe_bo *bo,
>  	/* Initialize purge advisory state */
>  	bo->purgeable.state = XE_MADV_PURGEABLE_WILLNEED;
>  
> -	drm_gem_private_object_init(&xe->drm, &bo->ttm.base, size);
> +	err = drm_gem_private_object_init(&xe->drm, &bo->ttm.base, size);
> +	if (err)
> +		return ERR_PTR(err);
>  
>  	if (resv) {
>  		ctx.allow_res_evict = !(flags & XE_BO_FLAG_NO_RESV_EVICT);

[Severity: Medium]
Can this error path leak the xe_bo struct? If xe_bo_init_locked() is called
with a NULL bo pointer, such as from xe_bo_create_locked(), it allocates a
new xe_bo structure internally. If drm_gem_private_object_init() then fails,
returning ERR_PTR(err) immediately means the newly allocated bo reference is 
lost before it can be freed with xe_bo_free().

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260827124910.2245-1-christian.koenig@amd.com?part=4

  reply	other threads:[~2026-08-27 13:19 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-27 12:38 Refcounting dma_resv v2 Christian König
2026-08-27 12:38 ` [PATCH 01/10] dma-buf: Add reference counting to dma_resv Christian König
2026-08-27 18:39   ` Andi Shyti
2026-08-28 18:21   ` Danilo Krummrich
2026-08-28 19:17     ` Matthew Brost
2026-08-28 19:34       ` Matthew Brost
2026-08-31  7:37         ` Christian König
2026-08-31 21:09           ` Matthew Brost
2026-08-31  7:31     ` Christian König
2026-08-27 12:38 ` [PATCH 02/10] dma-buf/tests: Convert st-dma-resv tests to use dma_resv_alloc Christian König
2026-08-27 13:08   ` sashiko-bot
2026-08-27 12:38 ` [PATCH 03/10] drm/gem: Add helper for drm_gem_object resv assignment Christian König
2026-08-27 13:22   ` sashiko-bot
2026-08-27 12:38 ` [PATCH 04/10] drm/gem: Convert drm_gem_private_object_init to return error code Christian König
2026-08-27 13:19   ` sashiko-bot [this message]
2026-08-31 20:59   ` Youssef Samir
2026-08-27 12:38 ` [PATCH 05/10] drm/gem: Use dynamic allocation for GEM object dma_resv Christian König
2026-08-27 13:13   ` sashiko-bot
2026-08-27 12:38 ` [PATCH 06/10] drm/mode_config: Use dma_resv_alloc for lockdep annotation Christian König
2026-08-27 13:02   ` sashiko-bot
2026-08-27 12:38 ` [PATCH 07/10] drm/xe: " Christian König
2026-08-27 13:04   ` sashiko-bot
2026-08-27 12:38 ` [PATCH 08/10] drm/i915/gt: Use dma_resv_alloc for VM reservation objects Christian König
2026-08-27 13:11   ` sashiko-bot
2026-08-27 12:38 ` [PATCH 09/10] drm/ttm/tests: Use dma_resv_alloc in test files Christian König
2026-08-27 13:12   ` sashiko-bot
2026-08-27 12:38 ` [PATCH 10/10] dma-buf: Inline dma_resv_init and remove allocated flag Christian König
2026-08-27 13:31   ` sashiko-bot
2026-08-27 13:39 ` ✗ Fi.CI.BUILD: failure for series starting with [01/10] dma-buf: Add reference counting to dma_resv Patchwork

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=20260827131915.40AC81F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=ckoenig.leichtzumerken@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.