From ddfd9c80e659669c9948d2929b7bce179fbbd3d5 Mon Sep 17 00:00:00 2001 From: Daniel Lezcano Date: Wed, 19 Apr 2023 10:33:42 +0200 Subject: [PATCH] ACPI: thermal: Move to dedicated function sysfs extra attr creation [Upstream commit a4b81715a58e0ddf10bc2df2185566b73b9ae616] The ACPI thermal driver creates extra sysfs attributes in its own directory pointing to the thermal zone it is related to and add a pointer to the sysfs ACPI thermal device from the thermal zone sysfs entry. This is very specific to this ACPI thermal driver, let's encapsulate the related creation/deletion code to group it inside a function we can identify later for removal if needed. Signed-off-by: Daniel Lezcano [ rjw: Subject adjustment, removal of trailing white space ] Signed-off-by: Rafael J. Wysocki Signed-off-by: zhaolichang <943677312@qq.com> --- drivers/acpi/thermal.c | 48 +++++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index 383c7029d3ce..2fe83c126914 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -856,6 +856,30 @@ static struct thermal_zone_device_ops acpi_thermal_zone_ops = { .notify = thermal_notify, }; +static int acpi_thermal_zone_sysfs_add(struct acpi_thermal *tz) +{ + int ret; + ret = sysfs_create_link(&tz->device->dev.kobj, + &tz->thermal_zone->device.kobj, "thermal_zone"); + + if (ret) + return ret; + + ret = sysfs_create_link(&tz->thermal_zone->device.kobj, + &tz->device->dev.kobj, "device"); + + if (ret) + sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone"); + + return ret; +} + +static void acpi_thermal_zone_sysfs_remove(struct acpi_thermal *tz) +{ + sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone"); + sysfs_remove_link(&tz->thermal_zone->device.kobj, "device"); +} + static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) { int trips = 0; @@ -889,32 +913,32 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) if (IS_ERR(tz->thermal_zone)) return -ENODEV; - result = sysfs_create_link(&tz->device->dev.kobj, - &tz->thermal_zone->device.kobj, "thermal_zone"); - if (result) - return result; - - result = sysfs_create_link(&tz->thermal_zone->device.kobj, - &tz->device->dev.kobj, "device"); + result = acpi_thermal_zone_sysfs_add(tz); if (result) return result; status = acpi_bus_attach_private_data(tz->device->handle, - tz->thermal_zone); - if (ACPI_FAILURE(status)) - return -ENODEV; + tz->thermal_zone); + if (ACPI_FAILURE(status)) { + result = -ENODEV; + goto remove_links; + } tz->tz_enabled = 1; dev_info(&tz->device->dev, "registered as thermal_zone%d\n", tz->thermal_zone->id); return 0; + +remove_links: + acpi_thermal_zone_sysfs_remove(tz); + + return result; } static void acpi_thermal_unregister_thermal_zone(struct acpi_thermal *tz) { - sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone"); - sysfs_remove_link(&tz->thermal_zone->device.kobj, "device"); + acpi_thermal_zone_sysfs_remove(tz); thermal_zone_device_unregister(tz->thermal_zone); tz->thermal_zone = NULL; acpi_bus_detach_private_data(tz->device->handle); -- Gitee