Skip to contentSkip to conversation

powercap/drivers/dtpm: Fix a double shift bug

PATCH In review Dan Carpenter 3 participants 5 messages Jan 6, 2021 – Jan 7, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 powercap/drivers/dtpm: Fix a double shift bug

The DTPM_POWER_LIMIT_FLAG is used for test_bit() etc which take a bit number so it should be bit 0. But currently it's set to BIT(0) then that is double shifted equivalent to BIT(BIT(0)). This doesn't cause a run time problem because it's done consistently.

Fixes a20d0ef97abf ("powercap/drivers/dtpm: Add API for dynamic thermal power management")
---
 drivers/powercap/dtpm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/powercap/dtpm.c +1 -1
index 0abcc439d728..d49df0569cd4 100644
@@ -24,7 +24,7 @@
 #include <linux/slab.h>
 #include <linux/mutex.h>
 
-#define DTPM_POWER_LIMIT_FLAG BIT(0)
+#define DTPM_POWER_LIMIT_FLAG 0
 
 static const char *constraint_name[] = {
 	"Instantaneous",
Signature · 1 line
2.29.2
#1 lore raw

PATCH 3/3 powercap/drivers/dtpm: Fix an IS_ERR() vs NULL check

The powercap_register_control_type() function never returns NULL, it returns error pointers on error so update this check.

Fixes a20d0ef97abf ("powercap/drivers/dtpm: Add API for dynamic thermal power management")
---
 drivers/powercap/dtpm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/powercap/dtpm.c +2 -2
index 470a1182b868..5a51cd34a7e8 100644
@@ -467,9 +467,9 @@ static int __init dtpm_init(void)
 	struct dtpm_descr **dtpm_descr;
 
 	pct = powercap_register_control_type(NULL, "dtpm", NULL);
-	if (!pct) {
+	if (IS_ERR(pct)) {
 		pr_err("Failed to register control type\n");
-		return -EINVAL;
+		return PTR_ERR(pct);
 	}
 
 	for_each_dtpm_table(dtpm_descr)
Signature · 1 line
2.29.2
Acked-by on v1 3/3
#2 lore raw

Re: [PATCH 3/3] powercap/drivers/dtpm: Fix an IS_ERR() vs NULL check

Quoted 5 lines · Dan Carpenter

The powercap_register_control_type() function never returns NULL, it returns error pointers on error so update this check.

Fixes a20d0ef97abf ("powercap/drivers/dtpm: Add API for dynamic thermal power management")

Thanks for these fixes.

--Daniel

Quoted 21 lines
---
 drivers/powercap/dtpm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/powercap/dtpm.c +2 -2
index 470a1182b868..5a51cd34a7e8 100644
@@ -467,9 +467,9 @@ static int __init dtpm_init(void)
 	struct dtpm_descr **dtpm_descr;
 
 	pct = powercap_register_control_type(NULL, "dtpm", NULL);
-	if (!pct) {
+	if (IS_ERR(pct)) {
 		pr_err("Failed to register control type\n");
-		return -EINVAL;
+		return PTR_ERR(pct);
 	}
 
 	for_each_dtpm_table(dtpm_descr)
Signature · 5 lines
<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
#3 lore raw

Re: [PATCH 3/3] powercap/drivers/dtpm: Fix an IS_ERR() vs NULL check

Quoted 11 lines · Daniel Lezcano
Quoted 5 lines · Dan Carpenter

The powercap_register_control_type() function never returns NULL, it returns error pointers on error so update this check.

Fixes a20d0ef97abf ("powercap/drivers/dtpm: Add API for dynamic thermal power management")

Thanks for these fixes.

All 3 patches applied, but as the original DTPM changes have not made it into 5.11-rc, all of this is 5.12 material now.

Acked-by on v1 1/3
#4 lore raw
In reply to Dan Carpenter
Quoted 7 lines · Dan Carpenter

The DTPM_POWER_LIMIT_FLAG is used for test_bit() etc which take a bit number so it should be bit 0. But currently it's set to BIT(0) then that is double shifted equivalent to BIT(BIT(0)). This doesn't cause a run time problem because it's done consistently.

Fixes a20d0ef97abf ("powercap/drivers/dtpm: Add API for dynamic thermal power management")
Quoted 18 lines
---
 drivers/powercap/dtpm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/powercap/dtpm.c +1 -1
index 0abcc439d728..d49df0569cd4 100644
@@ -24,7 +24,7 @@
 #include <linux/slab.h>
 #include <linux/mutex.h>
 
-#define DTPM_POWER_LIMIT_FLAG BIT(0)
+#define DTPM_POWER_LIMIT_FLAG 0
 
 static const char *constraint_name[] = {
 	"Instantaneous",
Signature · 5 lines
<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