ACPI: sysfs: Fix hotplug kobject cleanup on failure
PATCH 1/1 ACPI: sysfs: Fix hotplug kobject cleanup on failure
acpi_sysfs_init() creates the ACPI hotplug kobject and the force_remove sysfs file before creating the pm_profile file. If force_remove creation fails, the hotplug kobject is left behind. If pm_profile creation fails, both force_remove and the hotplug kobject are left behind.
Add the missing unwind paths so the partial hotplug sysfs state is removed before returning an error.
--- drivers/acpi/sysfs.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/acpi/sysfs.c +11 -1
@@ -1037,8 +1037,18 @@ int __init acpi_sysfs_init(void) result =sysfs_create_file (hotplug_kobj, &force_remove_attr.attr);if (result) -return result; + goto err_hotplug; result =sysfs_create_file (acpi_kobj, &pm_profile_attr.attr); +if (result) + goto err_force_remove; + +return 0 ; + +err_force_remove: +sysfs_remove_file (hotplug_kobj, &force_remove_attr.attr); +err_hotplug: +kobject_put (hotplug_kobj); + hotplug_kobj =NULL ;return result; }
Signature · 1 line
2.43.0
Rafael J. Wysocki (Intel)
maintainerQuoted 8 lines · Yuho Choi
acpi_sysfs_init()creates the ACPI hotplug kobject and theforce_removesysfs file before creating thepm_profilefile. Ifforce_removecreation fails, the hotplug kobject is left behind. Ifpm_profilecreation fails, bothforce_removeand the hotplug kobject are left behind.Add the missing unwind paths so the partial hotplug sysfs state is removed before returning an error.
But platform_profile does not really depend on the hotplug thing, so dropping it on pm_profile creation failure is not necessary.
Quoted 33 lines
Fixes 683058e315f0 ("ACPI / hotplug: Use device offline/online for graceful hot-removal")Signed-off-by Yuho Choi <[email protected]>--- drivers/acpi/sysfs.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)drivers/acpi/sysfs.c +11
-2@@ -1037,8 +1037,18 @@ int __init acpi_sysfs_init(void) result =sysfs_create_file (hotplug_kobj, &force_remove_attr.attr);if (result) -return result; + goto err_hotplug; result =sysfs_create_file (acpi_kobj, &pm_profile_attr.attr); +if (result) + goto err_force_remove; + +return 0 ; + +err_force_remove: +sysfs_remove_file (hotplug_kobj, &force_remove_attr.attr); +err_hotplug: +kobject_put (hotplug_kobj); + hotplug_kobj =NULL ;return result; } --2.43.0