mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: liupeng <liupeng01@kylinos.cn>
To: lyude@redhat.com, dakr@kernel.org
Cc: maarten.lankhorst@linux.intel.com, mripard@kernel.org,
	tzimmermann@suse.de, airlied@gmail.com, simona@ffwll.ch,
	linux@roeck-us.net, nouveau@karolherbst.de,
	dri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org,
	linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org,
	stable@vger.kernel.org, liupeng <liupeng01@kylinos.cn>
Subject: [PATCH v4 2/2] drm/nouveau: Fix memory leak in hwmon init error path
Date: Sat, 10 Oct 2026 10:20:06 +0800	[thread overview]
Message-ID: <20261010022006.28263-2-liupeng01@kylinos.cn> (raw)
In-Reply-To: <20261010022006.28263-1-liupeng01@kylinos.cn>

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 this by freeing the allocated memory and clearing the pointer on
the error path.

Fixes: b9ed919f1c8f ("drm/nouveau/drm/pm: remove everything except the hwmon interfaces to THERM")
Cc: stable@vger.kernel.org
Reviewed-by: Lyude Paul <lyude@redhat.com>
Signed-off-by: liupeng <liupeng01@kylinos.cn>
---
Changes in v4:
- Split the debugfs and hwmon fixes into two separate patches as
  requested by Danilo, since they are unrelated fixes with different
  Fixes: tags. No functional change to this fix.

 drivers/gpu/drm/nouveau/nouveau_hwmon.c | 2 ++
 1 file changed, 2 insertions(+)

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;
 	}
 
-- 
2.53.0


      reply	other threads:[~2026-10-10  2:20 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-24  9:05 [PATCH] drm/nouveau: Fix memory leaks in debugfs and hwmon init error paths liupeng
2026-09-17 22:10 ` lyude
2026-09-22  4:40   ` [PATCH v2] " liupeng
2026-10-08 21:45     ` lyude
2026-10-09 11:51       ` [PATCH v3] " liupeng
2026-10-09 21:35         ` lyude
2026-10-09 21:40           ` Danilo Krummrich
2026-10-09 21:43             ` lyude
2026-10-10  2:20               ` [PATCH v4 1/2] drm/nouveau: Fix memory leak in debugfs init error path liupeng
2026-10-10  2:20                 ` liupeng [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=20261010022006.28263-2-liupeng01@kylinos.cn \
    --to=liupeng01@kylinos.cn \
    --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=lyude@redhat.com \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=nouveau@karolherbst.de \
    --cc=nouveau@lists.freedesktop.org \
    --cc=simona@ffwll.ch \
    --cc=stable@vger.kernel.org \
    --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®