Skip to contentSkip to conversation

clk: fix clk_get on of_clk_get_by_name return check

PATCH Superseded Shawn Guo 4 participants 4 messages Jul 15, 2012 – Jul 17, 2012 Arm/clkdev support

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Shawn Guo

author
#0 lore raw

PATCH 1/1 clk: fix clk_get on of_clk_get_by_name return check

The commit 766e6a4 (clk: add DT clock binding support) plugs device tree clk lookup of_clk_get_by_name into clk_get, and fall on non-DT lookup clk_get_sys if DT lookup fails.

The return check on of_clk_get_by_name takes (clk != NULL) as a successful DT lookup. But it's not the case. For any system that does not define clk lookup in device tree, ERR_PTR(-ENOENT) will be returned, and consequently, all the client drivers calling clk_get in their probe functions will fail to probe with error code -ENOENT returned.

Fix the issue by checking of_clk_get_by_name return with !IS_ERR(clk).

---
 drivers/clk/clkdev.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/clk/clkdev.c +1 -1
index 20649b3..69085e0 100644
@@ -157,7 +157,7 @@ struct clk *clk_get(struct device *dev, const char *con_id)
 
 	if (dev) {
 		clk = of_clk_get_by_name(dev->of_node, con_id);
-		if (clk && __clk_get(clk))
+		if (!IS_ERR(clk) && __clk_get(clk))
 			return clk;
 	}
 
Signature · 1 line
1.7.5.4
#1 lore raw

PATCH 1/1 clk: fix clk_get on of_clk_get_by_name return check

Quoted 11 lines · Shawn Guo

The commit 766e6a4 (clk: add DT clock binding support) plugs device tree clk lookup of_clk_get_by_name into clk_get, and fall on non-DT lookup clk_get_sys if DT lookup fails.

The return check on of_clk_get_by_name takes (clk != NULL) as a successful DT lookup. But it's not the case. For any system that does not define clk lookup in device tree, ERR_PTR(-ENOENT) will be returned, and consequently, all the client drivers calling clk_get in their probe functions will fail to probe with error code -ENOENT returned.

Quoted 3 lines

Fix the issue by checking of_clk_get_by_name return with !IS_ERR(clk).

Thanks Shawn.

Quoted 18 lines
---
 drivers/clk/clkdev.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/clk/clkdev.c +1 -1
index 20649b3..69085e0 100644
@@ -157,7 +157,7 @@ struct clk *clk_get(struct device *dev, const char *con_id)
 
 	if (dev) {
 		clk = of_clk_get_by_name(dev->of_node, con_id);
-		if (clk && __clk_get(clk))
+		if (!IS_ERR(clk) && __clk_get(clk))
 			return clk;
 	}
 
#2 lore raw

PATCH 1/1 clk: fix clk_get on of_clk_get_by_name return check

In reply to Shawn Guo

Dear Shawn Guo,

Quoted 11 lines

The commit 766e6a4 (clk: add DT clock binding support) plugs device tree clk lookup of_clk_get_by_name into clk_get, and fall on non-DT lookup clk_get_sys if DT lookup fails.

The return check on of_clk_get_by_name takes (clk != NULL) as a successful DT lookup. But it's not the case. For any system that does not define clk lookup in device tree, ERR_PTR(-ENOENT) will be returned, and consequently, all the client drivers calling clk_get in their probe functions will fail to probe with error code -ENOENT returned.

Quoted 3 lines

Fix the issue by checking of_clk_get_by_name return with !IS_ERR(clk).

Quoted 9 lines
---
 drivers/clk/clkdev.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/clk/clkdev.c +0 -0
index 20649b3..69085e0 100644

drivers/clk/clkdev.c struct clk *clk_get(struct device *dev, const char · line 163

Quoted 8 lines
drivers/clk/clkdev.c +1 -1
@@ -157,7 +157,7 @@ struct clk *clk_get(struct device *dev, const char
 *con_id)
 
 	if (dev) {
 		clk = of_clk_get_by_name(dev->of_node, con_id);
-		if (clk && __clk_get(clk))
+		if (!IS_ERR(clk) && __clk_get(clk))
 			return clk;
 	}

Best regards,
Marek Vasut

#3 lore raw

PATCH 1/1 clk: fix clk_get on of_clk_get_by_name return check

In reply to Shawn Guo

This patch fixes the boot issue on mx28evk and apx4devkit.

Quoted 11 lines · Shawn Guo

The commit 766e6a4 (clk: add DT clock binding support) plugs device tree clk lookup of_clk_get_by_name into clk_get, and fall on non-DT lookup clk_get_sys if DT lookup fails.

The return check on of_clk_get_by_name takes (clk != NULL) as a successful DT lookup. But it's not the case. For any system that does not define clk lookup in device tree, ERR_PTR(-ENOENT) will be returned, and consequently, all the client drivers calling clk_get in their probe functions will fail to probe with error code -ENOENT returned.

Quoted 3 lines

Fix the issue by checking of_clk_get_by_name return with !IS_ERR(clk).

Best regards,
Lauri Hintsala

Quoted 18 lines
---
  drivers/clk/clkdev.c |    2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)
drivers/clk/clkdev.c +1 -1
index 20649b3..69085e0 100644
@@ -157,7 +157,7 @@ struct clk *clk_get(struct device *dev, const char *con_id)
 
  	if (dev) {
  		clk = of_clk_get_by_name(dev->of_node, con_id);
-		if (clk && __clk_get(clk))
+		if (!IS_ERR(clk) && __clk_get(clk))
  			return clk;
  	}