[CPUFREQ] drivers/cpufreq/cpufreq.c: Adjust error handling code involving cpufreq_cpu_put
After calling cpufreq_cpu_get, error handling code should call cpufreq_cpu_put. The semantic match that finds this problem is as follows: (http://www.emn.fr/x-info/coccinelle/) // <smpl> @r@ expression x,E; statement S; position p1,p2,p3; @@ ( if ((x = cpufreq_cpu_get@p1(...)) == NULL || ...) S | x = cpufreq_cpu_get@p1(...) ... when != x if (x == NULL || ...) S ) <... if@p3 (...) { ... when != cpufreq_cpu_put(x) when != if (x) { ... cpufreq_cpu_put(x); ...} return@p2 ...; } ...> ( return x; | return 0; | x = E | E = x | cpufreq_cpu_put(x) ) @exists@ position r.p1,r.p2,r.p3; expression x; int ret != 0; statement S; @@ * x = cpufreq_cpu_get@p1(...) <... * if@p3 (...) S ...> * return@p2 \(NULL\|ret\); // </smpl> Signed-off-by: Julia Lawall <julia@diku.dk> Signed-off-by: Dave Jones <davej@redhat.com>
This commit is contained in:
@@ -1467,20 +1467,22 @@ int cpufreq_driver_target(struct cpufreq_policy *policy,
|
|||||||
unsigned int target_freq,
|
unsigned int target_freq,
|
||||||
unsigned int relation)
|
unsigned int relation)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret = -EINVAL;
|
||||||
|
|
||||||
policy = cpufreq_cpu_get(policy->cpu);
|
policy = cpufreq_cpu_get(policy->cpu);
|
||||||
if (!policy)
|
if (!policy)
|
||||||
return -EINVAL;
|
goto no_policy;
|
||||||
|
|
||||||
if (unlikely(lock_policy_rwsem_write(policy->cpu)))
|
if (unlikely(lock_policy_rwsem_write(policy->cpu)))
|
||||||
return -EINVAL;
|
goto fail;
|
||||||
|
|
||||||
ret = __cpufreq_driver_target(policy, target_freq, relation);
|
ret = __cpufreq_driver_target(policy, target_freq, relation);
|
||||||
|
|
||||||
unlock_policy_rwsem_write(policy->cpu);
|
unlock_policy_rwsem_write(policy->cpu);
|
||||||
|
|
||||||
|
fail:
|
||||||
cpufreq_cpu_put(policy);
|
cpufreq_cpu_put(policy);
|
||||||
|
no_policy:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(cpufreq_driver_target);
|
EXPORT_SYMBOL_GPL(cpufreq_driver_target);
|
||||||
@@ -1717,13 +1719,17 @@ int cpufreq_update_policy(unsigned int cpu)
|
|||||||
{
|
{
|
||||||
struct cpufreq_policy *data = cpufreq_cpu_get(cpu);
|
struct cpufreq_policy *data = cpufreq_cpu_get(cpu);
|
||||||
struct cpufreq_policy policy;
|
struct cpufreq_policy policy;
|
||||||
int ret = 0;
|
int ret;
|
||||||
|
|
||||||
if (!data)
|
if (!data) {
|
||||||
return -ENODEV;
|
ret = -ENODEV;
|
||||||
|
goto no_policy;
|
||||||
|
}
|
||||||
|
|
||||||
if (unlikely(lock_policy_rwsem_write(cpu)))
|
if (unlikely(lock_policy_rwsem_write(cpu))) {
|
||||||
return -EINVAL;
|
ret = -EINVAL;
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
dprintk("updating policy for CPU %u\n", cpu);
|
dprintk("updating policy for CPU %u\n", cpu);
|
||||||
memcpy(&policy, data, sizeof(struct cpufreq_policy));
|
memcpy(&policy, data, sizeof(struct cpufreq_policy));
|
||||||
@@ -1750,7 +1756,9 @@ int cpufreq_update_policy(unsigned int cpu)
|
|||||||
|
|
||||||
unlock_policy_rwsem_write(cpu);
|
unlock_policy_rwsem_write(cpu);
|
||||||
|
|
||||||
|
fail:
|
||||||
cpufreq_cpu_put(data);
|
cpufreq_cpu_put(data);
|
||||||
|
no_policy:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(cpufreq_update_policy);
|
EXPORT_SYMBOL(cpufreq_update_policy);
|
||||||
|
Reference in New Issue
Block a user