Skip to contentSkip to conversation

cpufreq: cpufreq-cpu0: NULL is a valid regulator

PATCH In review Mark Brown 3 participants 3 messages Aug 9, 2013 – Aug 13, 2013 CPU frequency scaling framework

lore
Share & tools
lore

Mark Brown

author
#0 lore raw

PATCH 1/1 cpufreq: cpufreq-cpu0: NULL is a valid regulator

From: Mark Brown <[email protected]>

Since NULL could in theory be a valid regulator we ought to check for IS_ERR() rather than for NULL. In practice this is unlikely to be an issue but it's better for neatness.

---
 drivers/cpufreq/cpufreq-cpu0.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/cpufreq/cpufreq-cpu0.c +4 -5
index ad1fde2..09cd3a7 100644
@@ -69,7 +69,7 @@ static int cpu0_set_target(struct cpufreq_policy *policy,
 
 	cpufreq_notify_transition(policy, &freqs, CPUFREQ_PRECHANGE);
 
-	if (cpu_reg) {
+	if (!IS_ERR(cpu_reg)) {
 		rcu_read_lock();
 		opp = opp_find_freq_ceil(cpu_dev, &freq_Hz);
 		if (IS_ERR(opp)) {
@@ -90,7 +90,7 @@ static int cpu0_set_target(struct cpufreq_policy *policy,
 		 freqs.new / 1000, volt ? volt / 1000 : -1);
 
 	/* scaling up?  scale voltage before frequency */
-	if (cpu_reg && freqs.new > freqs.old) {
+	if (!IS_ERR(cpu_reg) && freqs.new > freqs.old) {
 		ret = regulator_set_voltage_tol(cpu_reg, volt, tol);
 		if (ret) {
 			pr_err("failed to scale voltage up: %d\n", ret);
@@ -102,14 +102,14 @@ static int cpu0_set_target(struct cpufreq_policy *policy,
 	ret = clk_set_rate(cpu_clk, freq_exact);
 	if (ret) {
 		pr_err("failed to set clock rate: %d\n", ret);
-		if (cpu_reg)
+		if (!IS_ERR(cpu_reg))
 			regulator_set_voltage_tol(cpu_reg, volt_old, tol);
 		freqs.new = freqs.old;
 		goto post_notify;
 	}
 
 	/* scaling down?  scale voltage after frequency */
-	if (cpu_reg && freqs.new < freqs.old) {
+	if (!IS_ERR(cpu_reg) && freqs.new < freqs.old) {
 		ret = regulator_set_voltage_tol(cpu_reg, volt, tol);
 		if (ret) {
 			pr_err("failed to scale voltage down: %d\n", ret);
@@ -210,7 +210,6 @@ static int cpu0_cpufreq_probe(struct platform_device *pdev)
 		}
 		pr_warn("failed to get cpu0 regulator: %ld\n",
 			PTR_ERR(cpu_reg));
-		cpu_reg = NULL;
 	}
 
 	cpu_clk = devm_clk_get(cpu_dev, NULL);
Signature · 1 line
1.8.4.rc1
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines · Mark Brown

From: Mark Brown <[email protected]>

Since NULL could in theory be a valid regulator we ought to check for IS_ERR() rather than for NULL. In practice this is unlikely to be an issue but it's better for neatness.

---
 drivers/cpufreq/cpufreq-cpu0.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

Makes sense.

#2 lore raw
Quoted 7 lines · Viresh Kumar
Quoted 6 lines · Mark Brown

From: Mark Brown <[email protected]>

Since NULL could in theory be a valid regulator we ought to check for IS_ERR() rather than for NULL. In practice this is unlikely to be an issue but it's better for neatness.

Quoted 8 lines
Quoted 4 lines
---
 drivers/cpufreq/cpufreq-cpu0.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

Makes sense.

Queued up for 3.12.

Thanks,
Rafael