From: Daniel Lezcano <daniel.lezcano@linaro.org>
To: "Rafael J. Wysocki" <rjw@rjwysocki.net>,
Linux PM <linux-pm@vger.kernel.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
"Zhang Rui" <rui.zhang@intel.com>,
"Lukasz Luba" <lukasz.luba@arm.com>,
"Peter Kästle" <peter@piie.net>
Subject: Re: [PATCH v1 2/2] thermal: sysfs: Add sanity checks for trip temperature and hysteresis
Date: Fri, 23 Aug 2024 17:26:00 +0200 [thread overview]
Message-ID: <cb8bbde9-1b13-4c63-960d-5846a319f5ea@linaro.org> (raw)
In-Reply-To: <7719509.EvYhyI6sBW@rjwysocki.net>
On 22/08/2024 21:48, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>
> Add sanity checks for new trip temperature and hysteresis values to
> trip_point_temp_store() and trip_point_hyst_store() to prevent trip
> point thresholds from falling below THERMAL_TEMP_INVALID.
>
> However, still allow user space to pass THERMAL_TEMP_INVALID as the
> new trip temperature value to invalidate the trip if necessary.
>
> Fixes: be0a3600aa1e ("thermal: sysfs: Rework the handling of trip point updates")
> Cc: 6.8+ <stable@vger.kernel.org> # 6.8+
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
> drivers/thermal/thermal_sysfs.c | 38 ++++++++++++++++++++++++++------------
> 1 file changed, 26 insertions(+), 12 deletions(-)
>
> Index: linux-pm/drivers/thermal/thermal_sysfs.c
> ===================================================================
> --- linux-pm.orig/drivers/thermal/thermal_sysfs.c
> +++ linux-pm/drivers/thermal/thermal_sysfs.c
> @@ -111,18 +111,25 @@ trip_point_temp_store(struct device *dev
>
> mutex_lock(&tz->lock);
>
> - if (temp != trip->temperature) {
> - if (tz->ops.set_trip_temp) {
> - ret = tz->ops.set_trip_temp(tz, trip, temp);
> - if (ret)
> - goto unlock;
> - }
> + if (temp == trip->temperature)
> + goto unlock;
>
> - thermal_zone_set_trip_temp(tz, trip, temp);
> + if (temp != THERMAL_TEMP_INVALID &&
> + temp <= trip->hysteresis + THERMAL_TEMP_INVALID) {
It seems to me the condition is hard to understand.
temp <= trip->hysteresis + THERMAL_TEMP_INVALID
==>
temp - trip->hysteresis <= THERMAL_TEMP_INVALID
Could be the test below simpler to understand ?
if (trip->hysteresis &&
temp - trip->hysteresis < THERMAL_TEMP_INVALID))
I think more sanity check may be needed also.
if (temp < THERMAL_TEMP_INVALID)
> + ret = -EINVAL;
> + goto unlock;
> + }
>
> - __thermal_zone_device_update(tz, THERMAL_TRIP_CHANGED);
> + if (tz->ops.set_trip_temp) {
> + ret = tz->ops.set_trip_temp(tz, trip, temp);
> + if (ret)
> + goto unlock;
> }
>
> + thermal_zone_set_trip_temp(tz, trip, temp);
> +
> + __thermal_zone_device_update(tz, THERMAL_TRIP_CHANGED);
> +
> unlock:
> mutex_unlock(&tz->lock);
>
> @@ -152,15 +159,22 @@ trip_point_hyst_store(struct device *dev
>
> mutex_lock(&tz->lock);
>
> - if (hyst != trip->hysteresis) {
> - thermal_zone_set_trip_hyst(tz, trip, hyst);
> + if (hyst == trip->hysteresis)
> + goto unlock;
>
> - __thermal_zone_device_update(tz, THERMAL_TRIP_CHANGED);
> + if (hyst + THERMAL_TEMP_INVALID >= trip->temperature) {
> + ret = -EINVAL;
> + goto unlock;
> }
>
> + thermal_zone_set_trip_hyst(tz, trip, hyst);
> +
> + __thermal_zone_device_update(tz, THERMAL_TRIP_CHANGED);
> +
> +unlock:
> mutex_unlock(&tz->lock);
>
> - return count;
> + return ret ? ret : count;
> }
>
> static ssize_t
>
>
>
--
<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
next prev parent reply other threads:[~2024-08-23 15:26 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-22 19:42 [PATCH v1 0/2] thermal: core: Two fixes for 6.12 Rafael J. Wysocki
2024-08-22 19:47 ` [PATCH v1 1/2] thermal: core: Fix rounding of delay jiffies Rafael J. Wysocki
2024-08-23 8:36 ` Daniel Lezcano
2024-08-22 19:48 ` [PATCH v1 2/2] thermal: sysfs: Add sanity checks for trip temperature and hysteresis Rafael J. Wysocki
2024-08-23 15:26 ` Daniel Lezcano [this message]
2024-08-23 16:39 ` Rafael J. Wysocki
2024-08-23 17:04 ` Rafael J. Wysocki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=cb8bbde9-1b13-4c63-960d-5846a319f5ea@linaro.org \
--to=daniel.lezcano@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=lukasz.luba@arm.com \
--cc=peter@piie.net \
--cc=rjw@rjwysocki.net \
--cc=rui.zhang@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®