public inbox for linux-acpi@vger.kernel.org
 help / color / mirror / Atom feed
From: Guangshuo Li <lgs201920130244@gmail.com>
To: "Rafael J. Wysocki" <rafael@kernel.org>,
	Len Brown <lenb@kernel.org>,
	linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Guangshuo Li <lgs201920130244@gmail.com>, stable@vger.kernel.org
Subject: [PATCH] ACPI: power: Use put_device() in power resource add error path
Date: Fri, 10 Apr 2026 18:34:51 +0800	[thread overview]
Message-ID: <20260410103451.2014607-1-lgs201920130244@gmail.com> (raw)

After device_initialize(), the lifetime of struct device is managed by
the driver core through reference counting.

acpi_add_power_resource() initializes device->dev via
acpi_init_device_object(), which installs acpi_release_power_resource()
as the release callback. If acpi_device_add() fails, however, the error
path calls acpi_release_power_resource() directly instead of dropping
the device reference with put_device().

This bypasses the normal device lifetime rules and frees the object
without releasing the reference acquired by device_initialize(), which
may lead to a refcount leak and potentially a use-after-free. Fix it by
calling put_device(&device->dev) and let the release callback handle
the final cleanup.

Fixes: 781d737c7466 ("ACPI: Drop power resources driver")
Cc: stable@vger.kernel.org
Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
---
 drivers/acpi/power.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/acpi/power.c b/drivers/acpi/power.c
index 361a7721a6a8..f96f954876a7 100644
--- a/drivers/acpi/power.c
+++ b/drivers/acpi/power.c
@@ -991,7 +991,7 @@ struct acpi_device *acpi_add_power_resource(acpi_handle handle)
 	return device;
 
  err:
-	acpi_release_power_resource(&device->dev);
+	put_device(&device->dev);
 	return NULL;
 }
 
-- 
2.43.0


             reply	other threads:[~2026-04-10 10:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-10 10:34 Guangshuo Li [this message]
2026-04-11 11:33 ` [PATCH] ACPI: power: Use put_device() in power resource add error path Rafael J. Wysocki

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=20260410103451.2014607-1-lgs201920130244@gmail.com \
    --to=lgs201920130244@gmail.com \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rafael@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