Re: [PATCH v1] ACPI: sysfs: Fix hotplug kobject cleanup on failure
From: Rafael J. Wysocki (Intel)
Date: Mon Jul 06 2026 - 15:34:29 EST
On Fri, Jul 3, 2026 at 1:26 AM Yuho Choi <dbgh9129@xxxxxxxxx> wrote:
>
> 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.
> Fixes: 683058e315f0 ("ACPI / hotplug: Use device offline/online for graceful hot-removal")
> Signed-off-by: Yuho Choi <dbgh9129@xxxxxxxxx>
> ---
> drivers/acpi/sysfs.c | 12 +++++++++++-
> 1 file changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
> index 908cc5c7e643..0b642ba1a526 100644
> --- a/drivers/acpi/sysfs.c
> +++ b/drivers/acpi/sysfs.c
> @@ -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
>