* [PATCH] PM: QoS: Add check to make sure CPU latency is non-negative
@ 2023-07-31 6:03 Clive Lin
2023-08-22 19:39 ` Rafael J. Wysocki
0 siblings, 1 reply; 2+ messages in thread
From: Clive Lin @ 2023-07-31 6:03 UTC (permalink / raw)
To: rafael, pavel, len.brown
Cc: linux-pm, linux-kernel, chung-kai.yang, ccj.yeh, clive.lin,
ching-hao.hsu
CPU latency should never be negative, which will be incorrectly high
when converted to unsigned data type. Commit 8d36694245f2 ("PM: QoS:
Add check to make sure CPU freq is non-negative") makes sure CPU freq
is non-negative to fix incorrect behavior in freq_qos. Adding a check
to make sure CPU latency is non-negative can prevent this problem
from happening in cpu_latency_qos.
Signed-off-by: Clive Lin <clive.lin@mediatek.com>
---
kernel/power/qos.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/kernel/power/qos.c b/kernel/power/qos.c
index 782d3b41c1f3..4244b069442e 100644
--- a/kernel/power/qos.c
+++ b/kernel/power/qos.c
@@ -220,6 +220,11 @@ static struct pm_qos_constraints cpu_latency_constraints = {
.type = PM_QOS_MIN,
};
+static inline bool cpu_latency_qos_value_invalid(s32 value)
+{
+ return value < 0 && value != PM_QOS_DEFAULT_VALUE;
+}
+
/**
* cpu_latency_qos_limit - Return current system-wide CPU latency QoS limit.
*/
@@ -263,7 +268,7 @@ static void cpu_latency_qos_apply(struct pm_qos_request *req,
*/
void cpu_latency_qos_add_request(struct pm_qos_request *req, s32 value)
{
- if (!req)
+ if (!req || cpu_latency_qos_value_invalid(value))
return;
if (cpu_latency_qos_request_active(req)) {
@@ -289,7 +294,7 @@ EXPORT_SYMBOL_GPL(cpu_latency_qos_add_request);
*/
void cpu_latency_qos_update_request(struct pm_qos_request *req, s32 new_value)
{
- if (!req)
+ if (!req || cpu_latency_qos_value_invalid(new_value))
return;
if (!cpu_latency_qos_request_active(req)) {
--
2.18.0
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] PM: QoS: Add check to make sure CPU latency is non-negative
2023-07-31 6:03 [PATCH] PM: QoS: Add check to make sure CPU latency is non-negative Clive Lin
@ 2023-08-22 19:39 ` Rafael J. Wysocki
0 siblings, 0 replies; 2+ messages in thread
From: Rafael J. Wysocki @ 2023-08-22 19:39 UTC (permalink / raw)
To: Clive Lin
Cc: rafael, pavel, len.brown, linux-pm, linux-kernel, chung-kai.yang,
ccj.yeh, ching-hao.hsu
On Mon, Jul 31, 2023 at 8:04 AM Clive Lin <clive.lin@mediatek.com> wrote:
>
> CPU latency should never be negative, which will be incorrectly high
> when converted to unsigned data type. Commit 8d36694245f2 ("PM: QoS:
> Add check to make sure CPU freq is non-negative") makes sure CPU freq
> is non-negative to fix incorrect behavior in freq_qos. Adding a check
> to make sure CPU latency is non-negative can prevent this problem
> from happening in cpu_latency_qos.
>
> Signed-off-by: Clive Lin <clive.lin@mediatek.com>
> ---
> kernel/power/qos.c | 9 +++++++--
> 1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/power/qos.c b/kernel/power/qos.c
> index 782d3b41c1f3..4244b069442e 100644
> --- a/kernel/power/qos.c
> +++ b/kernel/power/qos.c
> @@ -220,6 +220,11 @@ static struct pm_qos_constraints cpu_latency_constraints = {
> .type = PM_QOS_MIN,
> };
>
> +static inline bool cpu_latency_qos_value_invalid(s32 value)
> +{
> + return value < 0 && value != PM_QOS_DEFAULT_VALUE;
> +}
> +
> /**
> * cpu_latency_qos_limit - Return current system-wide CPU latency QoS limit.
> */
> @@ -263,7 +268,7 @@ static void cpu_latency_qos_apply(struct pm_qos_request *req,
> */
> void cpu_latency_qos_add_request(struct pm_qos_request *req, s32 value)
> {
> - if (!req)
> + if (!req || cpu_latency_qos_value_invalid(value))
> return;
>
> if (cpu_latency_qos_request_active(req)) {
> @@ -289,7 +294,7 @@ EXPORT_SYMBOL_GPL(cpu_latency_qos_add_request);
> */
> void cpu_latency_qos_update_request(struct pm_qos_request *req, s32 new_value)
> {
> - if (!req)
> + if (!req || cpu_latency_qos_value_invalid(new_value))
> return;
>
> if (!cpu_latency_qos_request_active(req)) {
> --
Applied (with some edits in the changelog) as 6.6 material, thanks!
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-08-22 19:39 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-31 6:03 [PATCH] PM: QoS: Add check to make sure CPU latency is non-negative Clive Lin
2023-08-22 19:39 ` Rafael J. Wysocki
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®