Skip to content

Commit a4b8171

Browse files
dlezcanorafaeljw
authored andcommitted
ACPI: thermal: Move to dedicated function sysfs extra attr creation
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 <daniel.lezcano@linaro.org> [ rjw: Subject adjustment, removal of trailing white space ] Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 66d39e7 commit a4b8171

1 file changed

Lines changed: 31 additions & 19 deletions

File tree

drivers/acpi/thermal.c

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -787,9 +787,34 @@ static struct thermal_zone_device_ops acpi_thermal_zone_ops = {
787787
.critical = acpi_thermal_zone_device_critical,
788788
};
789789

790+
static int acpi_thermal_zone_sysfs_add(struct acpi_thermal *tz)
791+
{
792+
struct device *tzdev = thermal_zone_device(tz->thermal_zone);
793+
int ret;
794+
795+
ret = sysfs_create_link(&tz->device->dev.kobj,
796+
&tzdev->kobj, "thermal_zone");
797+
if (ret)
798+
return ret;
799+
800+
ret = sysfs_create_link(&tzdev->kobj,
801+
&tz->device->dev.kobj, "device");
802+
if (ret)
803+
sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone");
804+
805+
return ret;
806+
}
807+
808+
static void acpi_thermal_zone_sysfs_remove(struct acpi_thermal *tz)
809+
{
810+
struct device *tzdev = thermal_zone_device(tz->thermal_zone);
811+
812+
sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone");
813+
sysfs_remove_link(&tzdev->kobj, "device");
814+
}
815+
790816
static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz)
791817
{
792-
struct device *tzdev;
793818
int trips = 0;
794819
int result;
795820
acpi_status status;
@@ -821,23 +846,15 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz)
821846
if (IS_ERR(tz->thermal_zone))
822847
return -ENODEV;
823848

824-
tzdev = thermal_zone_device(tz->thermal_zone);
825-
826-
result = sysfs_create_link(&tz->device->dev.kobj,
827-
&tzdev->kobj, "thermal_zone");
849+
result = acpi_thermal_zone_sysfs_add(tz);
828850
if (result)
829851
goto unregister_tzd;
830852

831-
result = sysfs_create_link(&tzdev->kobj,
832-
&tz->device->dev.kobj, "device");
833-
if (result)
834-
goto remove_tz_link;
835-
836853
status = acpi_bus_attach_private_data(tz->device->handle,
837854
tz->thermal_zone);
838855
if (ACPI_FAILURE(status)) {
839856
result = -ENODEV;
840-
goto remove_dev_link;
857+
goto remove_links;
841858
}
842859

843860
result = thermal_zone_device_enable(tz->thermal_zone);
@@ -851,10 +868,8 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz)
851868

852869
acpi_bus_detach:
853870
acpi_bus_detach_private_data(tz->device->handle);
854-
remove_dev_link:
855-
sysfs_remove_link(&tzdev->kobj, "device");
856-
remove_tz_link:
857-
sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone");
871+
remove_links:
872+
acpi_thermal_zone_sysfs_remove(tz);
858873
unregister_tzd:
859874
thermal_zone_device_unregister(tz->thermal_zone);
860875

@@ -863,10 +878,7 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz)
863878

864879
static void acpi_thermal_unregister_thermal_zone(struct acpi_thermal *tz)
865880
{
866-
struct device *tzdev = thermal_zone_device(tz->thermal_zone);
867-
868-
sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone");
869-
sysfs_remove_link(&tzdev->kobj, "device");
881+
acpi_thermal_zone_sysfs_remove(tz);
870882
thermal_zone_device_unregister(tz->thermal_zone);
871883
tz->thermal_zone = NULL;
872884
acpi_bus_detach_private_data(tz->device->handle);

0 commit comments

Comments
 (0)