[PATCH v1 11/11] thermal/acpi: Use the thermal zone parameter to specify the device link

From: Daniel Lezcano
Date: Tue Mar 07 2023 - 08:38:26 EST


The thermal framework can create a cyclic link between the driver and
the device via the thermal zone parameters when registering the
thermal zone.

As this option is supported by the thermal core code, let's use it and
remove the specific code in the ACPI driver. This change has the
benefit of self-encapsulate the thermal zone device structure.

Signed-off-by: Daniel Lezcano <daniel.lezcano@xxxxxxxxxx>
---
drivers/acpi/thermal.c | 24 ++++--------------------
1 file changed, 4 insertions(+), 20 deletions(-)

diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c
index 255efa73ed70..7d5c56564556 100644
--- a/drivers/acpi/thermal.c
+++ b/drivers/acpi/thermal.c
@@ -789,6 +789,7 @@ static struct thermal_zone_device_ops acpi_thermal_zone_ops = {

static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz)
{
+ struct thermal_zone_params tzp = { .linked_dev = &tz->device->dev };
int trips = 0;
int result;
acpi_status status;
@@ -808,33 +809,23 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz)

if (tz->trips.passive.flags.valid)
tz->thermal_zone = thermal_zone_device_register("acpitz", trips, 0, tz,
- &acpi_thermal_zone_ops, NULL,
+ &acpi_thermal_zone_ops, &tzp,
tz->trips.passive.tsp * 100,
tz->polling_frequency * 100);
else
tz->thermal_zone =
thermal_zone_device_register("acpitz", trips, 0, tz,
- &acpi_thermal_zone_ops, NULL,
+ &acpi_thermal_zone_ops, &tzp,
0, tz->polling_frequency * 100);

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)
- goto unregister_tzd;
-
- result = sysfs_create_link(&tz->thermal_zone->device.kobj,
- &tz->device->dev.kobj, "device");
- if (result)
- goto remove_tz_link;
-
status = acpi_bus_attach_private_data(tz->device->handle,
tz->thermal_zone);
if (ACPI_FAILURE(status)) {
result = -ENODEV;
- goto remove_dev_link;
+ goto unregister_tzd;
}

result = thermal_zone_device_enable(tz->thermal_zone);
@@ -848,20 +839,13 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz)

acpi_bus_detach:
acpi_bus_detach_private_data(tz->device->handle);
-remove_dev_link:
- sysfs_remove_link(&tz->thermal_zone->device.kobj, "device");
-remove_tz_link:
- sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone");
unregister_tzd:
thermal_zone_device_unregister(tz->thermal_zone);
-
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");
thermal_zone_device_unregister(tz->thermal_zone);
tz->thermal_zone = NULL;
acpi_bus_detach_private_data(tz->device->handle);
--
2.34.1