From: Mikko Perttunen <mperttunen@nvidia.com>
To: Thierry Reding <thierry.reding@kernel.org>,
David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
Jonathan Hunter <jonathanh@nvidia.com>,
dri-devel@lists.freedesktop.org, linux-tegra@vger.kernel.org,
linux-kernel@vger.kernel.org,
Guangshuo Li <lgs201920130244@gmail.com>
Cc: Guangshuo Li <lgs201920130244@gmail.com>
Subject: Re: [PATCH] drm/tegra: Finalize GEM object on initialization failure
Date: Wed, 15 Jul 2026 14:54:55 +0900 [thread overview]
Message-ID: <zoMtvLtqSfu7q9QMPT-kPg@nvidia.com> (raw)
In-Reply-To: <20260714131923.1575860-1-lgs201920130244@gmail.com>
On Tuesday, July 14, 2026 10:19 PM Guangshuo Li wrote:
> tegra_bo_alloc_object() allocates bo and passes its embedded GEM object
> to drm_gem_object_init().
>
> drm_gem_object_init() initializes the GEM private state before creating
> the shmem backing file. If the file creation fails, it returns an error
> with the reservation object and GPUVA mutex still initialized.
>
> The current error path directly frees bo, bypassing the matching GEM
> private-object cleanup. Finalize the partially initialized GEM object
> with drm_gem_private_object_fini() before freeing bo.
>
> This issue was found by a static analysis tool I am developing.
>
> Fixes: c28d4a317fef ("drm/tegra: gem: Extract tegra_bo_alloc_object()")
> Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
> ---
> drivers/gpu/drm/tegra/gem.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/tegra/gem.c b/drivers/gpu/drm/tegra/gem.c
> index 436394e04812..eb513cb7521c 100644
> --- a/drivers/gpu/drm/tegra/gem.c
> +++ b/drivers/gpu/drm/tegra/gem.c
> @@ -314,8 +314,10 @@ static struct tegra_bo *tegra_bo_alloc_object(struct drm_device *drm,
> size = round_up(size, PAGE_SIZE);
>
> err = drm_gem_object_init(drm, &bo->gem, size);
> - if (err < 0)
> + if (err < 0) {
> + drm_gem_private_object_fini(&bo->gem);
> goto free;
> + }
>
> err = drm_gem_create_mmap_offset(&bo->gem);
> if (err < 0)
> --
> 2.43.0
>
>
This looks correct, but a quick analysis shows a lot of drivers have
the same issue. I think it'd be a good idea to either
1. Fix drm_gem_object_init to clean up after itself (and update
callers accordingly)
or
2. Fix the same issue at other call sites of drm_gem_object_init
as well in one go.
In any case,
Reviewed-by: Mikko Perttunen <mperttunen@nvidia.com>
Thank you
Mikko
prev parent reply other threads:[~2026-07-15 5:55 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-14 13:19 [PATCH] drm/tegra: Finalize GEM object on initialization failure Guangshuo Li
2026-07-15 5:54 ` Mikko Perttunen [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=zoMtvLtqSfu7q9QMPT-kPg@nvidia.com \
--to=mperttunen@nvidia.com \
--cc=airlied@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=jonathanh@nvidia.com \
--cc=lgs201920130244@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tegra@vger.kernel.org \
--cc=simona@ffwll.ch \
--cc=thierry.reding@kernel.org \
/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