mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Wentao Liang <vulab@iscas.ac.cn>
To: Sebastian Reichel <sre@kernel.org>
Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
	Wentao Liang <vulab@iscas.ac.cn>,
	stable@vger.kernel.org
Subject: [PATCH] power: reset: reboot-mode: drop the device reference on unregister
Date: Tue,  3 Nov 2026 10:55:43 +0000	[thread overview]
Message-ID: <20261103105543.1394542-1-vulab@iscas.ac.cn> (raw)

reboot_mode_unregister_device() looks the device up with
class_find_device(), which takes a reference that the caller has to drop
with put_device().  The function only calls device_unregister(), which
drops the reference taken when the device was registered.  The lookup
reference therefore leaks and the struct device allocated by
device_create() is never freed.

Drop the class_find_device() reference before unregistering, the same
way device_destroy() does.

Fixes: cfaf0a90789a ("power: reset: reboot-mode: Expose sysfs for registered reboot_modes")
Cc: stable@vger.kernel.org
Assisted-by: DeepSeek-V4.1-Flash and OpenAI Codex
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
 drivers/power/reset/reboot-mode.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/power/reset/reboot-mode.c b/drivers/power/reset/reboot-mode.c
index 3611bed341e1..db55b71f0c7e 100644
--- a/drivers/power/reset/reboot-mode.c
+++ b/drivers/power/reset/reboot-mode.c
@@ -249,6 +249,8 @@ static inline void reboot_mode_unregister_device(struct reboot_mode_driver *rebo
 		return;
 
 	priv = dev_get_drvdata(reboot_mode_device);
+	/* matches class_find_device() above */
+	put_device(reboot_mode_device);
 	device_unregister(reboot_mode_device);
 
 	if (!priv)
-- 
2.34.1


             reply	other threads:[~2026-11-03 10:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-03 10:55 Wentao Liang [this message]
2026-11-03 11:10 ` Krzysztof Kozlowski

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=20261103105543.1394542-1-vulab@iscas.ac.cn \
    --to=vulab@iscas.ac.cn \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=sre@kernel.org \
    --cc=stable@vger.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

all inboxes | Powered by JetHome®