Skip to contentSkip to conversation

ACPI: sysfs: Fix hotplug kobject cleanup on failure

PATCH In review Yuho Choi 2 participants 2 messages Jul 2 – Jul 6 ACPI

lore
Share & tools
lore

Yuho Choi

author
#0 lore raw

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.

Fixes 683058e315f0 ("ACPI / hotplug: Use device offline/online for graceful hot-removal")
---
 drivers/acpi/sysfs.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/acpi/sysfs.c +11 -1
index 908cc5c7e643..0b642ba1a526 100644
@@ -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
#1 lore raw
Quoted 8 lines · Yuho Choi

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.

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")
---
 drivers/acpi/sysfs.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/acpi/sysfs.c +11 -2
index 908cc5c7e643..0b642ba1a526 100644
@@ -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