Skip to contentSkip to conversation

clk: have clk_get always return -ENOENT on missing clock

PATCH Applied Ahmad Fatoum 2 participants 2 messages Sep 18, 2023 – Sep 21, 2023 Arm/clkdev support

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 clk: have clk_get always return -ENOENT on missing clock

Currently, clk_get(dev, NULL) returns -ENOENT on missing clock, but clk_get(dev, "missing-named-clock") returns -EINVAL. This went by unnoticed so far as most consumers either require a clock or don't, but with the addition of clk_get_optional, it's important that clk_get() return value is uniform.

Therefore align clk_get with Linux and always fall through to clk_get_sys() if getting clock over DT is not possible. Failing clk_get_sys() returns -ENOENT always, ensuring we can't end up with -EINVAL as before while keeping of_clk_get_by_name return value as it is under Linux.

---
Please order before commit ("clk: implement clk_get_optional helper") currently 8b013ac8ec69 in next.

---
 drivers/clk/clkdev.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/clk/clkdev.c +2 -2
index 68c6ac36a0c8..dbe998b6af35 100644
@@ -176,9 +176,9 @@ struct clk *clk_get(struct device *dev, const char *con_id)
 	if (!IS_ERR(clk))
 		return clk;
 
-	if (dev) {
+	if (dev && dev->of_node) {
 		clk = of_clk_get_by_name(dev->of_node, con_id);
-		if (!IS_ERR(clk) || PTR_ERR(clk) != -ENOENT)
+		if (!IS_ERR(clk) || PTR_ERR(clk) == -EPROBE_DEFER)
 			return clk;
 	}
 
Signature · 1 line
2.39.2
Applied
#1 lore raw
Quoted 11 lines · Ahmad Fatoum

Currently, clk_get(dev, NULL) returns -ENOENT on missing clock, but clk_get(dev, "missing-named-clock") returns -EINVAL. This went by unnoticed so far as most consumers either require a clock or don't, but with the addition of clk_get_optional, it's important that clk_get() return value is uniform.

Therefore align clk_get with Linux and always fall through to clk_get_sys() if getting clock over DT is not possible. Failing clk_get_sys() returns -ENOENT always, ensuring we can't end up with -EINVAL as before while keeping of_clk_get_by_name return value as it is under Linux.

Quoted 7 lines

---
Please order before commit ("clk: implement clk_get_optional helper") currently 8b013ac8ec69 in next.

---
 drivers/clk/clkdev.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Applied, thanks

Sascha

Quoted 22 lines
drivers/clk/clkdev.c +2 -2
index 68c6ac36a0c8..dbe998b6af35 100644
@@ -176,9 +176,9 @@ struct clk *clk_get(struct device *dev, const char *con_id)
 	if (!IS_ERR(clk))
 		return clk;
 
-	if (dev) {
+	if (dev && dev->of_node) {
 		clk = of_clk_get_by_name(dev->of_node, con_id);
-		if (!IS_ERR(clk) || PTR_ERR(clk) != -ENOENT)
+		if (!IS_ERR(clk) || PTR_ERR(clk) == -EPROBE_DEFER)
 			return clk;
 	}
 
Signature · 1 line
2.39.2
Signature · 4 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |