[v1,4/7] ACPI: thermal: Hold thermal_check_lock around trip updates

Message ID 21958338.EfDdHjke4D@kreacher
State New
Headers
Series ACPI: thermal: Use trip point table to register thermal zones |

Commit Message

Rafael J. Wysocki July 18, 2023, 6:06 p.m. UTC
  From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

There is a race condition between acpi_thermal_trips_update() and
acpi_thermal_check_fn(), because the trip points may get updated while
the latter is running which in theory may lead to inconsistent results.
For example, if two trips are updated together, using the temperature
value of one of them from before the update and the temperature value
of the other one from after the update may not lead to the expected
outcome.

To address this, make acpi_thermal_trips_update() hold thermal_check_lock
across the entire update of trip points.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/acpi/thermal.c |    4 ++++
 1 file changed, 4 insertions(+)
  

Patch

Index: linux-pm/drivers/acpi/thermal.c
===================================================================
--- linux-pm.orig/drivers/acpi/thermal.c
+++ linux-pm/drivers/acpi/thermal.c
@@ -193,6 +193,8 @@  static int acpi_thermal_trips_update(str
 	struct acpi_handle_list devices;
 	bool valid = false;
 	int i;
+	
+	mutex_lock(&tz->thermal_check_lock);
 
 	/* Critical Shutdown */
 	if (flag & ACPI_TRIPS_CRITICAL) {
@@ -395,6 +397,8 @@  static int acpi_thermal_trips_update(str
 		}
 	}
 
+	mutex_unlock(&tz->thermal_check_lock);
+
 	return 0;
 }