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)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 10 Jan 2024 16:16:55 +0000 (17:16 +0100)
commit17f449600a98a18709e7f1c85546523d07480b79
treede98ab1cde8508e9edea3e515c7ac8e0c9c70de8
parent04ebb29dc9aabd4c71f5f796e9fa7fee7c477456
ACPI: thermal: Fix acpi_thermal_unregister_thermal_zone() cleanup

[ Upstream commit 4b27d5c420335dad7aea1aa6e799fe1d05c63b7e ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/acpi/thermal.c