aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/cpufreq
diff options
context:
space:
mode:
authorJulia Lawall <julia@diku.dk>2008-07-25 16:44:53 -0400
committerDave Jones <davej@redhat.com>2008-10-09 13:52:43 -0400
commitf1829e4a371f26430185a9d5b97b8d9d19824e08 (patch)
treee93626b049d174430d1431708398a90a4b756ed5 /drivers/cpufreq
parent888a794cacd8950ac6be701db20b62a4ab2ce90c (diff)
[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>
Diffstat (limited to 'drivers/cpufreq')
-rw-r--r--drivers/cpufreq/cpufreq.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 8a67f16987db..9bbdc258624c 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -1467,20 +1467,22 @@ int cpufreq_driver_target(struct cpufreq_policy *policy,
1467 unsigned int target_freq, 1467 unsigned int target_freq,
1468 unsigned int relation) 1468 unsigned int relation)
1469{ 1469{
1470 int ret; 1470 int ret = -EINVAL;
1471 1471
1472 policy = cpufreq_cpu_get(policy->cpu); 1472 policy = cpufreq_cpu_get(policy->cpu);
1473 if (!policy) 1473 if (!policy)
1474 return -EINVAL; 1474 goto no_policy;
1475 1475
1476 if (unlikely(lock_policy_rwsem_write(policy->cpu))) 1476 if (unlikely(lock_policy_rwsem_write(policy->cpu)))
1477 return -EINVAL; 1477 goto fail;
1478 1478
1479 ret = __cpufreq_driver_target(policy, target_freq, relation); 1479 ret = __cpufreq_driver_target(policy, target_freq, relation);
1480 1480
1481 unlock_policy_rwsem_write(policy->cpu); 1481 unlock_policy_rwsem_write(policy->cpu);
1482 1482
1483fail:
1483 cpufreq_cpu_put(policy); 1484 cpufreq_cpu_put(policy);
1485no_policy:
1484 return ret; 1486 return ret;
1485} 1487}
1486EXPORT_SYMBOL_GPL(cpufreq_driver_target); 1488EXPORT_SYMBOL_GPL(cpufreq_driver_target);
@@ -1717,13 +1719,17 @@ int cpufreq_update_policy(unsigned int cpu)
1717{ 1719{
1718 struct cpufreq_policy *data = cpufreq_cpu_get(cpu); 1720 struct cpufreq_policy *data = cpufreq_cpu_get(cpu);
1719 struct cpufreq_policy policy; 1721 struct cpufreq_policy policy;
1720 int ret = 0; 1722 int ret;
1721 1723
1722 if (!data) 1724 if (!data) {
1723 return -ENODEV; 1725 ret = -ENODEV;
1726 goto no_policy;
1727 }
1724 1728
1725 if (unlikely(lock_policy_rwsem_write(cpu))) 1729 if (unlikely(lock_policy_rwsem_write(cpu))) {
1726 return -EINVAL; 1730 ret = -EINVAL;
1731 goto fail;
1732 }
1727 1733
1728 dprintk("updating policy for CPU %u\n", cpu); 1734 dprintk("updating policy for CPU %u\n", cpu);
1729 memcpy(&policy, data, sizeof(struct cpufreq_policy)); 1735 memcpy(&policy, data, sizeof(struct cpufreq_policy));
@@ -1750,7 +1756,9 @@ int cpufreq_update_policy(unsigned int cpu)
1750 1756
1751 unlock_policy_rwsem_write(cpu); 1757 unlock_policy_rwsem_write(cpu);
1752 1758
1759fail:
1753 cpufreq_cpu_put(data); 1760 cpufreq_cpu_put(data);
1761no_policy:
1754 return ret; 1762 return ret;
1755} 1763}
1756EXPORT_SYMBOL(cpufreq_update_policy); 1764EXPORT_SYMBOL(cpufreq_update_policy);