diff mbox series

[v2,1/1] PM: QoS: Add check to make sure CPU freq is non-negative

Message ID 20220714134342.3498384-1-quic_kshivnan@quicinc.com (mailing list archive)
State Changes Requested, archived
Headers show
Series [v2,1/1] PM: QoS: Add check to make sure CPU freq is non-negative | expand

Commit Message

Shivnandan Kumar July 14, 2022, 1:43 p.m. UTC
CPU frequency should never be negative.
	If some client driver calls freq_qos_update_request with some
	value greater than INT_MAX, then it will set max CPU freq at
	fmax but it will add plist node with some negative priority.
	plist node has priority from INT_MIN (highest) to INT_MAX
	(lowest). Once priority is set as negative, another client
	will not be able to reduce CPU frequency. Adding check to
	make sure CPU freq is non-negative will fix this problem.

Signed-off-by: Shivnandan Kumar <quic_kshivnan@quicinc.com>

---
v1->v2
	-addressed comments from Rafael
	-changed commit text accordingly

 kernel/power/qos.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Rafael J. Wysocki July 14, 2022, 6:45 p.m. UTC | #1
On Thu, Jul 14, 2022 at 3:44 PM Shivnandan Kumar
<quic_kshivnan@quicinc.com> wrote:
>
>         CPU frequency should never be negative.
>         If some client driver calls freq_qos_update_request with some
>         value greater than INT_MAX, then it will set max CPU freq at
>         fmax but it will add plist node with some negative priority.
>         plist node has priority from INT_MIN (highest) to INT_MAX
>         (lowest). Once priority is set as negative, another client
>         will not be able to reduce CPU frequency. Adding check to
>         make sure CPU freq is non-negative will fix this problem.

The changelog doesn't match the patch any more, please rewrite it.

>
> Signed-off-by: Shivnandan Kumar <quic_kshivnan@quicinc.com>
>
> ---
> v1->v2
>         -addressed comments from Rafael
>         -changed commit text accordingly
>
>  kernel/power/qos.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/power/qos.c b/kernel/power/qos.c
> index ec7e1e85923e..27e6596f287a 100644
> --- a/kernel/power/qos.c
> +++ b/kernel/power/qos.c
> @@ -531,7 +531,7 @@ int freq_qos_add_request(struct freq_constraints *qos,
>  {
>         int ret;
>
> -       if (IS_ERR_OR_NULL(qos) || !req)
> +       if (IS_ERR_OR_NULL(qos) || !req || value < FREQ_QOS_MIN_DEFAULT_VALUE)
>                 return -EINVAL;
>
>         if (WARN(freq_qos_request_active(req),
> @@ -563,7 +563,7 @@ EXPORT_SYMBOL_GPL(freq_qos_add_request);
>   */
>  int freq_qos_update_request(struct freq_qos_request *req, s32 new_value)
>  {
> -       if (!req)
> +       if (!req || new_value < FREQ_QOS_MIN_DEFAULT_VALUE)
>                 return -EINVAL;
>
>         if (WARN(!freq_qos_request_active(req),
> --
> 2.25.1
>
diff mbox series

Patch

diff --git a/kernel/power/qos.c b/kernel/power/qos.c
index ec7e1e85923e..27e6596f287a 100644
--- a/kernel/power/qos.c
+++ b/kernel/power/qos.c
@@ -531,7 +531,7 @@  int freq_qos_add_request(struct freq_constraints *qos,
 {
 	int ret;
 
-	if (IS_ERR_OR_NULL(qos) || !req)
+	if (IS_ERR_OR_NULL(qos) || !req || value < FREQ_QOS_MIN_DEFAULT_VALUE)
 		return -EINVAL;
 
 	if (WARN(freq_qos_request_active(req),
@@ -563,7 +563,7 @@  EXPORT_SYMBOL_GPL(freq_qos_add_request);
  */
 int freq_qos_update_request(struct freq_qos_request *req, s32 new_value)
 {
-	if (!req)
+	if (!req || new_value < FREQ_QOS_MIN_DEFAULT_VALUE)
 		return -EINVAL;
 
 	if (WARN(!freq_qos_request_active(req),