Skip to contentSkip to conversation

cpufreq: Fix an IS_ERR() vs NULL bug in spear1340_set_cpu_rate()

PATCH Superseded Dan Carpenter 3 participants 5 messages Jul 10 – Jul 13

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cpufreq: Fix an IS_ERR() vs NULL bug in spear1340_set_cpu_rate()

The clk_get_parent() function doesn't return error pointers, it returns NULL on error. Update the error checking to match.

Fixes 420993221175 ("cpufreq: SPEAr: Add CPUFreq driver")
---
 drivers/cpufreq/spear-cpufreq.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/cpufreq/spear-cpufreq.c +2 -2
index 81a0780b2ebf..ffe5eda82f0b 100644
@@ -79,9 +79,9 @@ static int spear1340_set_cpu_rate(struct clk *sys_pclk, unsigned long newfreq)
 	int ret = 0;
 
 	sys_clk = clk_get_parent(spear_cpufreq.clk);
-	if (IS_ERR(sys_clk)) {
+	if (!sys_clk) {
 		pr_err("failed to get cpu's parent (sys) clock\n");
-		return PTR_ERR(sys_clk);
+		return -EINVAL;
 	}
 
 	/* Set the rate of the source clock before changing the parent */
Signature · 1 line
2.53.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Dan Carpenter

The clk_get_parent() function doesn't return error pointers, it returns NULL on error. Update the error checking to match.

Fixes 420993221175 ("cpufreq: SPEAr: Add CPUFreq driver")

Nice catch, thanks for the fix.

Nit: the subject is too generic and can be misread as a cpufreq core fix. It is better to scope it to the driver, e.g. "cpufreq: spear: ...".

With that:

Quoted 20 lines
---
  drivers/cpufreq/spear-cpufreq.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/cpufreq/spear-cpufreq.c +2 -2
index 81a0780b2ebf..ffe5eda82f0b 100644
@@ -79,9 +79,9 @@ static int spear1340_set_cpu_rate(struct clk *sys_pclk, unsigned long newfreq)
  	int ret = 0;
 
  	sys_clk = clk_get_parent(spear_cpufreq.clk);
-	if (IS_ERR(sys_clk)) {
+	if (!sys_clk) {
  		pr_err("failed to get cpu's parent (sys) clock\n");
-		return PTR_ERR(sys_clk);
+		return -EINVAL;
  	}
 
  	/* Set the rate of the source clock before changing the parent */
Signature · 2 lines
Thx and BRs,
Zhongqiu Han
maintainer
#2 lore raw
Quoted 3 lines · Zhongqiu Han
Quoted 2 lines · Dan Carpenter

The clk_get_parent() function doesn't return error pointers, it returns NULL on error. Update the error checking to match.

origin/master:include/linux/clk.h

/**
* clk_get_parent - get the parent clock source for this clock
* @clk: clock source
*
* Returns struct clk corresponding to parent clock source, or
* valid IS_ERR() condition containing errno.
*/
struct clk *clk_get_parent(struct clk *clk);

I think this is the source of the confusion.

Quoted 8 lines
Quoted 3 lines
Fixes 420993221175 ("cpufreq: SPEAr: Add CPUFreq driver")

Nice catch, thanks for the fix.

Nit: the subject is too generic and can be misread as a cpufreq core fix. It is better to scope it to the driver, e.g. "cpufreq: spear: ...".

Right.

Signature · 1 line
viresh
#3 lore raw
Quoted 16 lines · Viresh Kumar
Quoted 3 lines · Zhongqiu Han
Quoted 2 lines · Dan Carpenter

The clk_get_parent() function doesn't return error pointers, it returns NULL on error. Update the error checking to match.

origin/master:include/linux/clk.h

/**
* clk_get_parent - get the parent clock source for this clock
* @clk: clock source
*
* Returns struct clk corresponding to parent clock source, or
* valid IS_ERR() condition containing errno.
*/
struct clk *clk_get_parent(struct clk *clk);

Quoted 2 lines

I think this is the source of the confusion.

I'll send a separate patch to update that documentation.

regards,
dan carpenter

#4 lore raw
In reply to Zhongqiu Han
Quoted 4 lines · Zhongqiu Han
Quoted 3 lines · Dan Carpenter

The clk_get_parent() function doesn't return error pointers, it returns NULL on error. Update the error checking to match.

Quoted 8 lines
Quoted 2 lines
Fixes 420993221175 ("cpufreq: SPEAr: Add CPUFreq driver")

Nice catch, thanks for the fix.

Nit: the subject is too generic and can be misread as a cpufreq core fix. It is better to scope it to the driver, e.g. "cpufreq: spear: ...".

Oops. Sorry.

regards,
dan carpenter