]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
ACPI: scan: Use acpi_dev_put() in object add error paths
authorGuangshuo Li <lgs201920130244@gmail.com>
Mon, 13 Apr 2026 13:53:43 +0000 (21:53 +0800)
committerRafael J. Wysocki <rjw@rjwysocki.net>
Wed, 15 Apr 2026 14:43:58 +0000 (16:43 +0200)
After acpi_init_device_object(), the lifetime of struct acpi_device is
managed by the driver core through reference counting.

Both acpi_add_power_resource() and acpi_add_single_object() call
acpi_init_device_object() and then invoke acpi_device_add(). If that
fails, their error paths call the release callback directly instead of
dropping the device reference through acpi_dev_put().

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.

The issue was identified by a static analysis tool I developed and
confirmed by manual review.

Fix both error paths by using acpi_dev_put() and let the release
callback handle the final cleanup.

Fixes: 781d737c7466 ("ACPI: Drop power resources driver")
Fixes: 718fb0de8ff88 ("ACPI: fix NULL bug for HID/UID string")
Cc: All applicable <stable@vger.kernel.org>
Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
Link: https://patch.msgid.link/20260413135343.2884481-1-lgs201920130244@gmail.com
Signed-off-by: Rafael J. Wysocki <rjw@rjwysocki.net>
drivers/acpi/power.c
drivers/acpi/scan.c

index 6b1680ec369435fdc028652f0da32a6f7d01990e..d4131c184be8e64a63c56de544bc8a4195458dbb 100644 (file)
@@ -987,7 +987,7 @@ struct acpi_device *acpi_add_power_resource(acpi_handle handle)
        return device;
 
  err:
-       acpi_release_power_resource(&device->dev);
+       acpi_dev_put(device);
        return NULL;
 }
 
index e8cdbdb46fdb46e989ff2f6045904e456c219f8d..530547cda8b2866ad1aa39dc3a26a66d8ffa3df1 100644 (file)
@@ -1900,7 +1900,7 @@ static int acpi_add_single_object(struct acpi_device **child,
                result = acpi_device_add(device);
 
        if (result) {
-               acpi_device_release(&device->dev);
+               acpi_dev_put(device);
                return result;
        }