Skip to contentSkip to conversation

powercap/dtpm_devfreq: Fix error check against dev_pm_qos_add_request()

PATCH Applied Yuan Can 3 participants 3 messages Oct 18, 2024 – Oct 21, 2024

Subsystems (2)
lore
Share & tools
lore

Yuan Can

author
#0 lore raw

PATCH 1/1 powercap/dtpm_devfreq: Fix error check against dev_pm_qos_add_request()

The caller of the function dev_pm_qos_add_request() checks again a non zero value but dev_pm_qos_add_request() can return '1' if the request already exists. Therefore, the setup function fails while the QoS request actually did not failed.

Fix that by changing the check against a negative value like all the other callers of the function.

Fixes e44655617317 ("powercap/drivers/dtpm: Add dtpm devfreq with energy model support")
---
 drivers/powercap/dtpm_devfreq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/powercap/dtpm_devfreq.c +1 -1
index f40bce8176df..d1dff6ccab12 100644
@@ -178,7 +178,7 @@ static int __dtpm_devfreq_setup(struct devfreq *devfreq, struct dtpm *parent)
 	ret = dev_pm_qos_add_request(dev, &dtpm_devfreq->qos_req,
 				     DEV_PM_QOS_MAX_FREQUENCY,
 				     PM_QOS_MAX_FREQUENCY_DEFAULT_VALUE);
-	if (ret) {
+	if (ret < 0) {
 		pr_err("Failed to add QoS request: %d\n", ret);
 		goto out_dtpm_unregister;
 	}
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw

Hi Yuan,

Quoted 19 lines · Yuan Can

The caller of the function dev_pm_qos_add_request() checks again a non zero value but dev_pm_qos_add_request() can return '1' if the request already exists. Therefore, the setup function fails while the QoS request actually did not failed.

Fix that by changing the check against a negative value like all the other callers of the function.

Fixes e44655617317 ("powercap/drivers/dtpm: Add dtpm devfreq with energy model support")
---
  drivers/powercap/dtpm_devfreq.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/powercap/dtpm_devfreq.c +0 -0
index f40bce8176df..d1dff6ccab12 100644

drivers/powercap/dtpm_devfreq.c static int __dtpm_devfreq_setup(struct devfreq *devfreq, struct dtpm *parent) · line 184

Quoted 8 lines
drivers/powercap/dtpm_devfreq.c +1 -1
@@ -178,7 +178,7 @@ static int __dtpm_devfreq_setup(struct devfreq *devfreq, struct dtpm *parent)
  	ret = dev_pm_qos_add_request(dev, &dtpm_devfreq->qos_req,
  				     DEV_PM_QOS_MAX_FREQUENCY,
  				     PM_QOS_MAX_FREQUENCY_DEFAULT_VALUE);
-	if (ret) {
+	if (ret < 0) {
  		pr_err("Failed to add QoS request: %d\n", ret);
  		goto out_dtpm_unregister;
  	}

Good catch thanks!
Indeed in the doc of that API there is '1' as return value. I will check other places of that QoS usage.

maintainer Applied
#2 lore raw
Quoted 37 lines · Lukasz Luba

Hi Yuan,

Quoted 19 lines · Yuan Can

The caller of the function dev_pm_qos_add_request() checks again a non zero value but dev_pm_qos_add_request() can return '1' if the request already exists. Therefore, the setup function fails while the QoS request actually did not failed.

Fix that by changing the check against a negative value like all the other callers of the function.

Fixes e44655617317 ("powercap/drivers/dtpm: Add dtpm devfreq with energy model support")
---
  drivers/powercap/dtpm_devfreq.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/powercap/dtpm_devfreq.c +0 -0
index f40bce8176df..d1dff6ccab12 100644

drivers/powercap/dtpm_devfreq.c static int __dtpm_devfreq_setup(struct devfreq *devfreq, struct dtpm *parent) · line 184

Quoted 8 lines
drivers/powercap/dtpm_devfreq.c +1 -1
@@ -178,7 +178,7 @@ static int __dtpm_devfreq_setup(struct devfreq *devfreq, struct dtpm *parent)
      ret = dev_pm_qos_add_request(dev, &dtpm_devfreq->qos_req,
                                   DEV_PM_QOS_MAX_FREQUENCY,
                                   PM_QOS_MAX_FREQUENCY_DEFAULT_VALUE);
-     if (ret) {
+     if (ret < 0) {
              pr_err("Failed to add QoS request: %d\n", ret);
              goto out_dtpm_unregister;
      }

Good catch thanks!
Indeed in the doc of that API there is '1' as return value. I will check other places of that QoS usage.

Quoted 1 line

Applied as 6.12-rc material, thanks!