From: Rafael J. Wysocki Date: Thu, 11 Jul 2024 12:39:02 +0000 (+0200) Subject: thermal: core: Add sanity checks for polling_delay and passive_delay X-Git-Tag: v6.11-rc1~174^2~1^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3669716401921c4c545ac2998d7c67f9727ee056;p=thirdparty%2Flinux.git thermal: core: Add sanity checks for polling_delay and passive_delay 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. Signed-off-by: Rafael J. Wysocki Reviewed-by: Daniel Lezcano Link: https://patch.msgid.link/5802156.DvuYhMxLoT@rjwysocki.net --- diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 7139f729a83d4..24e0520340f67 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -1390,6 +1390,14 @@ thermal_zone_device_register_with_trips(const char *type, 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);