Skip to contentSkip to conversation

thermal: core: Add sanity checks for polling_delay and passive_delay

PATCH In review Rafael J. Wysocki 2 participants 2 messages Jul 11, 2024 Thermal

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 thermal: core: Add sanity checks for polling_delay and passive_delay

From: Rafael J. Wysocki <[email protected]>

If polling_delay is nonzero and passive_delay is greater than polling_delay, the thermal zone temperature will be updated less often when tz->passive is nonzero, which is not as expected. Make the thermal zone registration fail with -EINVAL in that case as this is a clear thermal zone configuration mistake.

If polling_delay is nonzero and passive_delay is 0, which is regarded as a valid thermal zone configuration, the thermal zone will use polling except when tz->passive is nonzero. However, the expected behavior in that case is to continue temperature polling with the same delay value regardless of tz->passive, so set passive_delay to the polling_delay value then.

---

This supersedes

https://lore.kernel.org/linux-pm/[email protected]/

---
 drivers/thermal/thermal_core.c |    8 ++++++++
 1 file changed, 8 insertions(+)
drivers/thermal/thermal_core.c +8 -0
Index: linux-pm/drivers/thermal/thermal_core.c
===================================================================
@@ -1391,6 +1391,14 @@ thermal_zone_device_register_with_trips(
 	if (num_trips > 0 && !trips)
 		return ERR_PTR(-EINVAL);
 
+	if (polling_delay) {
+		if (passive_delay > polling_delay)
+			return ERR_PTR(-EINVAL);
+
+		if (!passive_delay)
+			passive_delay = polling_delay;
+	}
+
 	if (!thermal_class)
 		return ERR_PTR(-ENODEV);
 
Reviewed-by on v3 1/1
#1 lore raw
Quoted 15 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

If polling_delay is nonzero and passive_delay is greater than polling_delay, the thermal zone temperature will be updated less often when tz->passive is nonzero, which is not as expected. Make the thermal zone registration fail with -EINVAL in that case as this is a clear thermal zone configuration mistake.

If polling_delay is nonzero and passive_delay is 0, which is regarded as a valid thermal zone configuration, the thermal zone will use polling except when tz->passive is nonzero. However, the expected behavior in that case is to continue temperature polling with the same delay value regardless of tz->passive, so set passive_delay to the polling_delay value then.

Quoted 2 lines

---

Quoted 31 lines

This supersedes

https://lore.kernel.org/linux-pm/[email protected]/

---
  drivers/thermal/thermal_core.c |    8 ++++++++
  1 file changed, 8 insertions(+)

Index: linux-pm/drivers/thermal/thermal_core.c
===================================================================

drivers/thermal/thermal_core.c +8 -0
@@ -1391,6 +1391,14 @@ thermal_zone_device_register_with_trips(
  	if (num_trips > 0 && !trips)
  		return ERR_PTR(-EINVAL);
 
+	if (polling_delay) {
+		if (passive_delay > polling_delay)
+			return ERR_PTR(-EINVAL);
+
+		if (!passive_delay)
+			passive_delay = polling_delay;
+	}
+
  	if (!thermal_class)
  		return ERR_PTR(-ENODEV);
 
Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog