]> git.itanic.dy.fi Git - linux-stable/commitdiff
ACPI: thermal: Fix acpi_thermal_unregister_thermal_zone() cleanup
authorDan Carpenter <dan.carpenter@linaro.org>
Tue, 31 Oct 2023 09:53:06 +0000 (12:53 +0300)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Tue, 31 Oct 2023 16:50:00 +0000 (17:50 +0100)
The acpi_thermal_unregister_thermal_zone() is paired with
acpi_thermal_register_thermal_zone() so it should mirror it.  It should
clean up all the resources that the register function allocated and
leave the stuff that was allocated elsewhere.

Unfortunately, it doesn't call thermal_zone_device_disable().  Also it
calls kfree(tz->trip_table) when it shouldn't.  That was allocated in
acpi_thermal_add().  Putting the kfree() here leads to a double free
in the acpi_thermal_add() clean up function.

Likewise, the acpi_thermal_remove() should mirror acpi_thermal_add() so
it should have an explicit kfree(tz->trip_table) as well.

Fixes: ec23c1c462de ("ACPI: thermal: Use trip point table to register thermal zones")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/acpi/thermal.c

index c3143ee5e825ff3e57468ac7e6339323779ef779..d4fdf8e163a3de4287ecdeb30a600427db473725 100644 (file)
@@ -736,9 +736,9 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz,
 
 static void acpi_thermal_unregister_thermal_zone(struct acpi_thermal *tz)
 {
+       thermal_zone_device_disable(tz->thermal_zone);
        acpi_thermal_zone_sysfs_remove(tz);
        thermal_zone_device_unregister(tz->thermal_zone);
-       kfree(tz->trip_table);
        tz->thermal_zone = NULL;
 }
 
@@ -1001,7 +1001,7 @@ static void acpi_thermal_remove(struct acpi_device *device)
 
        flush_workqueue(acpi_thermal_pm_queue);
        acpi_thermal_unregister_thermal_zone(tz);
-
+       kfree(tz->trip_table);
        acpi_thermal_free_thermal_zone(tz);
 }