From: lyude@redhat.com
To: liupeng <liupeng01@kylinos.cn>,
Danilo Krummrich <dakr@kernel.org>,
Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Maxime Ripard <mripard@kernel.org>,
Thomas Zimmermann <tzimmermann@suse.de>,
David Airlie <airlied@gmail.com>,
Simona Vetter <simona@ffwll.ch>,
Guenter Roeck <linux@roeck-us.net>,
"open list:DRM DRIVER FOR NVIDIA GEFORCE/QUADRO GPUS"
<dri-devel@lists.freedesktop.org>,
"open list:DRM DRIVER FOR NVIDIA GEFORCE/QUADRO GPUS"
<nouveau@lists.freedesktop.org>,
open list <linux-kernel@vger.kernel.org>,
"open list:HARDWARE
""MONITORING:Keyword:(devm_)?hwmon_device_(un)?register(|_with_groups|_with_info)"
<linux-hwmon@vger.kernel.org>
Subject: Re: [PATCH] drm/nouveau: Fix memory leaks in debugfs and hwmon init error paths
Date: Thu, 17 Sep 2026 18:10:05 -0400 [thread overview]
Message-ID: <ff3015a1c4b08088b0638b00670e86d612a27978.camel@redhat.com> (raw)
In-Reply-To: <20260824090505.49913-1-liupeng01@kylinos.cn>
Mind adding the proper Fixes: tags and Cc: tags here?
On Mon, 2026-08-24 at 17:05 +0800, liupeng wrote:
> In nouveau_debugfs_init(), if nvif_object_ctor() fails, the
> previously
> allocated drm->debugfs is leaked because the function returns the
> error code directly.
>
> In nouveau_hwmon_init(), if hwmon_device_register_with_info() fails,
> the allocated hwmon structure is leaked because the function returns
> the error code directly.
>
> Fix both by freeing the allocated memory and clearing the pointer on
> the error paths.
>
> Signed-off-by: liupeng <liupeng01@kylinos.cn>
> ---
> drivers/gpu/drm/nouveau/nouveau_debugfs.c | 15 ++++++++++++---
> drivers/gpu/drm/nouveau/nouveau_hwmon.c | 2 ++
> 2 files changed, 14 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/nouveau/nouveau_debugfs.c
> b/drivers/gpu/drm/nouveau/nouveau_debugfs.c
> index 47d5579c568d..88223931f382 100644
> --- a/drivers/gpu/drm/nouveau/nouveau_debugfs.c
> +++ b/drivers/gpu/drm/nouveau/nouveau_debugfs.c
> @@ -295,13 +295,22 @@ nouveau_drm_debugfs_init(struct drm_minor
> *minor)
> int
> nouveau_debugfs_init(struct nouveau_drm *drm)
> {
> + int ret;
> +
> drm->debugfs = kzalloc_obj(*drm->debugfs);
> if (!drm->debugfs)
> return -ENOMEM;
>
> - return nvif_object_ctor(&drm->client.device.object,
> "debugfsCtrl", 0,
> - NVIF_CLASS_CONTROL, NULL, 0,
> - &drm->debugfs->ctrl);
> + ret = nvif_object_ctor(&drm->client.device.object,
> "debugfsCtrl", 0,
> + NVIF_CLASS_CONTROL, NULL, 0,
> + &drm->debugfs->ctrl);
> + if (ret) {
> + kfree(drm->debugfs);
> + drm->debugfs = NULL;
> + return ret;
> + }
> +
> + return 0;
> }
>
> void
> diff --git a/drivers/gpu/drm/nouveau/nouveau_hwmon.c
> b/drivers/gpu/drm/nouveau/nouveau_hwmon.c
> index 726397ab035d..ffbe7f542ab0 100644
> --- a/drivers/gpu/drm/nouveau/nouveau_hwmon.c
> +++ b/drivers/gpu/drm/nouveau/nouveau_hwmon.c
> @@ -697,6 +697,8 @@ nouveau_hwmon_init(struct drm_device *dev)
> if (IS_ERR(hwmon_dev)) {
> ret = PTR_ERR(hwmon_dev);
> NV_ERROR(drm, "Unable to register hwmon device:
> %d\n", ret);
> + drm->hwmon = NULL;
> + kfree(hwmon);
> return ret;
> }
>
prev parent reply other threads:[~2026-09-17 22:10 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-24 9:05 liupeng
2026-09-17 22:10 ` lyude [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=ff3015a1c4b08088b0638b00670e86d612a27978.camel@redhat.com \
--to=lyude@redhat.com \
--cc=airlied@gmail.com \
--cc=dakr@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=liupeng01@kylinos.cn \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=nouveau@lists.freedesktop.org \
--cc=simona@ffwll.ch \
--cc=tzimmermann@suse.de \
/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®