ACPI: scan: fix bus ID cleanup on device_add() failures

When device_add() fails after acpi_device_set_name() has allocated an
instance ID and a new acpi_device_bus_id has been linked into
acpi_bus_id_list, the rollback path only removes wakeup_list and
detaches the ACPI handle data.

That leaves the bus-ID bookkeeping behind and keeps the allocated
instance number consumed.

Move the bus-ID cleanup and wakeup-list removal into a single helper.

Use it from both the normal device teardown path and the device_add()
rollback path. The wakeup list node is initialized before registration,
so it can be deleted without checking whether the device is wakeup-
capable like in the original teardown path.

Fixes: d783156ea3 ("ACPI / scan: Define non-empty device removal handler")
Signed-off-by: Hongyan Xu <getshell@seu.edu.cn>
[ rjw: Rename acpi_device_del_list() to acpi_device_cleanup() ]
[ rjw: Subject and changelog edits ]
Link: https://patch.msgid.link/20260808085943.526-1-getshell@seu.edu.cn
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
This commit is contained in:
Hongyan Xu
2026-08-08 16:59:42 +08:00
committed by Rafael J. Wysocki
parent f234fdaae1
commit a414485ebc

View File

@@ -524,12 +524,10 @@ static void acpi_device_release(struct device *dev)
kfree(acpi_dev);
}
static void acpi_device_del(struct acpi_device *device)
static void acpi_device_cleanup(struct acpi_device *device)
{
struct acpi_device_bus_id *acpi_device_bus_id;
mutex_lock(&acpi_device_lock);
list_for_each_entry(acpi_device_bus_id, &acpi_bus_id_list, node)
if (!strcmp(acpi_device_bus_id->bus_id,
acpi_device_hid(device))) {
@@ -544,6 +542,13 @@ static void acpi_device_del(struct acpi_device *device)
}
list_del(&device->wakeup_list);
}
static void acpi_device_del(struct acpi_device *device)
{
mutex_lock(&acpi_device_lock);
acpi_device_cleanup(device);
mutex_unlock(&acpi_device_lock);
@@ -803,7 +808,7 @@ int acpi_device_add(struct acpi_device *device)
err:
mutex_lock(&acpi_device_lock);
list_del(&device->wakeup_list);
acpi_device_cleanup(device);
err_unlock:
mutex_unlock(&acpi_device_lock);