Skip to contentSkip to conversation

cpufreq: unlock when failing cpufreq_update_policy()

PATCH Superseded Aaron Plattner 3 participants 6 messages Jun 18, 2014 CPU frequency scaling framework

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cpufreq: unlock when failing cpufreq_update_policy()

Commit bd0fa9bb455d introduced a failure path to cpufreq_update_policy() if cpufreq_driver->get(cpu) returns NULL. However, it jumps to the 'no_policy' label, which exits without unlocking any of the locks the function acquired earlier. This causes later calls into cpufreq to hang.

Fix this by creating a new 'unlock' label and jumping to that instead.

Fixes bd0fa9bb455d ("cpufreq: Return error if ->get() failed in cpufreq_update_policy()")
Cc Viresh Kumar <[email protected]>
Cc Rafael J. Wysocki <[email protected]>

---
I haven't reproduced this problem so I couldn't test it, but the bug and its solution seem obvious enough.

 drivers/cpufreq/cpufreq.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/cpufreq/cpufreq.c +2 -1
index aed2b0cb83dc..5b6d04f3b9ea 100644
@@ -2264,7 +2264,7 @@ int cpufreq_update_policy(unsigned int cpu)
 		new_policy.cur = cpufreq_driver->get(cpu);
 		if (WARN_ON(!new_policy.cur)) {
 			ret = -EIO;
-			goto no_policy;
+			goto unlock;
 		}
 
 		if (!policy->cur) {
@@ -2279,6 +2279,7 @@ int cpufreq_update_policy(unsigned int cpu)
 
 	ret = cpufreq_set_policy(policy, &new_policy);
 
+unlock:
 	up_write(&policy->rwsem);
 
 	cpufreq_cpu_put(policy);
Signature · 1 line
2.0.0
maintainer
#1 lore raw
Quoted 33 lines · Aaron Plattner

Commit bd0fa9bb455d introduced a failure path to cpufreq_update_policy() if cpufreq_driver->get(cpu) returns NULL. However, it jumps to the 'no_policy' label, which exits without unlocking any of the locks the function acquired earlier. This causes later calls into cpufreq to hang.

Fix this by creating a new 'unlock' label and jumping to that instead.

Fixes bd0fa9bb455d ("cpufreq: Return error if ->get() failed in cpufreq_update_policy()")
Cc Viresh Kumar <[email protected]>
Cc Rafael J. Wysocki <[email protected]>

---
I haven't reproduced this problem so I couldn't test it, but the bug and its solution seem obvious enough.

 drivers/cpufreq/cpufreq.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/cpufreq/cpufreq.c +1 -1
index aed2b0cb83dc..5b6d04f3b9ea 100644
@@ -2264,7 +2264,7 @@ int cpufreq_update_policy(unsigned int cpu)
                new_policy.cur = cpufreq_driver->get(cpu);
                if (WARN_ON(!new_policy.cur)) {
                        ret = -EIO;
-                       goto no_policy;
+                       goto unlock;
                }
 
                if (!policy->cur) {

drivers/cpufreq/cpufreq.c int cpufreq_update_policy(unsigned int cpu) · line 2285

Quoted 7 lines
drivers/cpufreq/cpufreq.c +1 -0
@@ -2279,6 +2279,7 @@ int cpufreq_update_policy(unsigned int cpu)
 
        ret = cpufreq_set_policy(policy, &new_policy);
 
+unlock:
        up_write(&policy->rwsem);
 
        cpufreq_cpu_put(policy);

Hmm, yes we do have a problem here but the code became a bit ugly now.. Can you please consider this diff instead?

drivers/cpufreq/cpufreq.c +3 -5
index aed2b0c..6caced5 100644
@@ -2242,10 +2242,8 @@ int cpufreq_update_policy(unsigned int cpu)
        struct cpufreq_policy new_policy;
        int ret;
 
-       if (!policy) {
-               ret = -ENODEV;
-               goto no_policy;
-       }
+       if (!policy)
+               return = -ENODEV;
 
        down_write(&policy->rwsem);
 
@@ -2279,10 +2277,10 @@ int cpufreq_update_policy(unsigned int cpu)
 
        ret = cpufreq_set_policy(policy, &new_policy);
 
+no_policy:
        up_write(&policy->rwsem);
 
        cpufreq_cpu_put(policy);
-no_policy:
        return ret;
 }
 EXPORT_SYMBOL(cpufreq_update_policy);
#2 lore raw
Quoted 50 lines · Viresh Kumar
Quoted 33 lines · Aaron Plattner

Commit bd0fa9bb455d introduced a failure path to cpufreq_update_policy() if cpufreq_driver->get(cpu) returns NULL. However, it jumps to the 'no_policy' label, which exits without unlocking any of the locks the function acquired earlier. This causes later calls into cpufreq to hang.

Fix this by creating a new 'unlock' label and jumping to that instead.

Fixes bd0fa9bb455d ("cpufreq: Return error if ->get() failed in cpufreq_update_policy()")
Cc Viresh Kumar <[email protected]>
Cc Rafael J. Wysocki <[email protected]>

---
I haven't reproduced this problem so I couldn't test it, but the bug and its solution seem obvious enough.

  drivers/cpufreq/cpufreq.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/cpufreq/cpufreq.c +1 -1
index aed2b0cb83dc..5b6d04f3b9ea 100644
@@ -2264,7 +2264,7 @@ int cpufreq_update_policy(unsigned int cpu)
                 new_policy.cur = cpufreq_driver->get(cpu);
                 if (WARN_ON(!new_policy.cur)) {
                         ret = -EIO;
-                       goto no_policy;
+                       goto unlock;
                 }
 
                 if (!policy->cur) {

drivers/cpufreq/cpufreq.c int cpufreq_update_policy(unsigned int cpu) · line 2285

Quoted 7 lines
drivers/cpufreq/cpufreq.c +1 -0
@@ -2279,6 +2279,7 @@ int cpufreq_update_policy(unsigned int cpu)
 
         ret = cpufreq_set_policy(policy, &new_policy);
 
+unlock:
         up_write(&policy->rwsem);
 
         cpufreq_cpu_put(policy);

Hmm, yes we do have a problem here but the code became a bit ugly now.. Can you please consider this diff instead?

drivers/cpufreq/cpufreq.c +0 -0
index aed2b0c..6caced5 100644

drivers/cpufreq/cpufreq.c int cpufreq_update_policy(unsigned int cpu) · line 2246

Quoted 9 lines
drivers/cpufreq/cpufreq.c +2 -4
@@ -2242,10 +2242,8 @@ int cpufreq_update_policy(unsigned int cpu)
         struct cpufreq_policy new_policy;
         int ret;
 
-       if (!policy) {
-               ret = -ENODEV;
-               goto no_policy;
-       }
+       if (!policy)
+               return = -ENODEV;

I assume you meant "return -ENODEV"?

drivers/cpufreq/cpufreq.c int cpufreq_update_policy(unsigned int cpu) · line 2280

Quoted 7 lines
drivers/cpufreq/cpufreq.c +1 -0
         down_write(&policy->rwsem);
 
@@ -2279,10 +2277,10 @@ int cpufreq_update_policy(unsigned int cpu)
 
         ret = cpufreq_set_policy(policy, &new_policy);
 
+no_policy:

'no_policy' implied to me that policy was NULL, so this label should still be renamed to 'unlock'. I'll send out a v2 that does this.

Quoted 8 lines
drivers/cpufreq/cpufreq.c +0 -1
         up_write(&policy->rwsem);
 
         cpufreq_cpu_put(policy);
-no_policy:
         return ret;
  }
  EXPORT_SYMBOL(cpufreq_update_policy);
Signature · 1 line
Aaron
maintainer
#3 lore raw
Quoted 1 line · Aaron Plattner

I assume you meant "return -ENODEV"?

Yeah, sorry :)

Quoted 11 lines

drivers/cpufreq/cpufreq.c int cpufreq_update_policy(unsigned int cpu) · line 2280

Quoted 7 lines
         down_write(&policy->rwsem);
drivers/cpufreq/cpufreq.c +1 -0
@@ -2279,10 +2277,10 @@ int cpufreq_update_policy(unsigned int cpu)
 
         ret = cpufreq_set_policy(policy, &new_policy);
 
+no_policy:

'no_policy' implied to me that policy was NULL, so this label should still be renamed to 'unlock'. I'll send out a v2 that does this.

Yeah.

#4 lore raw

PATCH v2 1/1 cpufreq: unlock when failing cpufreq_update_policy()

In reply to Aaron Plattner

Commit bd0fa9bb455d introduced a failure path to cpufreq_update_policy() if cpufreq_driver->get(cpu) returns NULL. However, it jumps to the 'no_policy' label, which exits without unlocking any of the locks the function acquired earlier. This causes later calls into cpufreq to hang.

Fix this by creating a new 'unlock' label and jumping to that instead.

v2: Delete the no_policy label and just return early if policy is NULL.

Fixes bd0fa9bb455d ("cpufreq: Return error if ->get() failed in cpufreq_update_policy()")
Cc Viresh Kumar <[email protected]>
Cc Rafael J. Wysocki <[email protected]>

---
v1 of this was tested by the user affected by the problem, but I don't have his email address so I can't add it as a Tested-by line.

 drivers/cpufreq/cpufreq.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/cpufreq/cpufreq.c +4 -6
index aed2b0cb83dc..62259d27f03e 100644
@@ -2242,10 +2242,8 @@ int cpufreq_update_policy(unsigned int cpu)
 	struct cpufreq_policy new_policy;
 	int ret;
 
-	if (!policy) {
-		ret = -ENODEV;
-		goto no_policy;
-	}
+	if (!policy)
+		return -ENODEV;
 
 	down_write(&policy->rwsem);
 
@@ -2264,7 +2262,7 @@ int cpufreq_update_policy(unsigned int cpu)
 		new_policy.cur = cpufreq_driver->get(cpu);
 		if (WARN_ON(!new_policy.cur)) {
 			ret = -EIO;
-			goto no_policy;
+			goto unlock;
 		}
 
 		if (!policy->cur) {
@@ -2279,10 +2277,10 @@ int cpufreq_update_policy(unsigned int cpu)
 
 	ret = cpufreq_set_policy(policy, &new_policy);
 
+unlock:
 	up_write(&policy->rwsem);
 
 	cpufreq_cpu_put(policy);
-no_policy:
 	return ret;
 }
 EXPORT_SYMBOL(cpufreq_update_policy);
Signature · 1 line
2.0.0
#5 lore raw
Quoted 7 lines · Aaron Plattner

Commit bd0fa9bb455d introduced a failure path to cpufreq_update_policy() if cpufreq_driver->get(cpu) returns NULL. However, it jumps to the 'no_policy' label, which exits without unlocking any of the locks the function acquired earlier. This causes later calls into cpufreq to hang.

Fix this by creating a new 'unlock' label and jumping to that instead.

Quoted 7 lines

v2: Delete the no_policy label and just return early if policy is NULL.

Fixes bd0fa9bb455d ("cpufreq: Return error if ->get() failed in cpufreq_update_policy()")
Cc Viresh Kumar <[email protected]>
Cc Rafael J. Wysocki <[email protected]>

Applied, thanks!

Quoted 46 lines

---
v1 of this was tested by the user affected by the problem, but I don't have his email address so I can't add it as a Tested-by line.

 drivers/cpufreq/cpufreq.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/cpufreq/cpufreq.c +4 -6
index aed2b0cb83dc..62259d27f03e 100644
@@ -2242,10 +2242,8 @@ int cpufreq_update_policy(unsigned int cpu)
 	struct cpufreq_policy new_policy;
 	int ret;
 
-	if (!policy) {
-		ret = -ENODEV;
-		goto no_policy;
-	}
+	if (!policy)
+		return -ENODEV;
 
 	down_write(&policy->rwsem);
 
@@ -2264,7 +2262,7 @@ int cpufreq_update_policy(unsigned int cpu)
 		new_policy.cur = cpufreq_driver->get(cpu);
 		if (WARN_ON(!new_policy.cur)) {
 			ret = -EIO;
-			goto no_policy;
+			goto unlock;
 		}
 
 		if (!policy->cur) {
@@ -2279,10 +2277,10 @@ int cpufreq_update_policy(unsigned int cpu)
 
 	ret = cpufreq_set_policy(policy, &new_policy);
 
+unlock:
 	up_write(&policy->rwsem);
 
 	cpufreq_cpu_put(policy);
-no_policy:
 	return ret;
 }
 EXPORT_SYMBOL(cpufreq_update_policy);
Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.