diff mbox series

[v2] clk: fixed: handle failed clk setup

Message ID 20231026105023.573674-1-emas@bang-olufsen.dk (mailing list archive)
State Under Review
Headers show
Series [v2] clk: fixed: handle failed clk setup | expand

Commit Message

Emil Abildgaard Svendsen Oct. 26, 2023, 10:50 a.m. UTC
From: Emil Abildgaard Svendsen <EMAS@bang-olufsen.dk>

When initializing clock providers "of_clk_init" will try and init
parents first. But if parent clock is provided by a platform driver it
can't. Then clocks will be forced on and OF_POPULATED flag will be set
blindly. So if setup failes e.g. with -EPROBE_DEFER the clock will not
be probed later on.

This patch will clear the OF_POPULATED flag if clock setup failes.

Signed-off-by: Emil Svendsen <emas@bang-olufsen.dk>
---
v2:
 - Fix spelling mistake in commit message

 drivers/clk/clk-fixed-factor.c | 19 +++++++++++--------
 drivers/clk/clk-fixed-rate.c   | 11 ++++++++++-
 2 files changed, 21 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/drivers/clk/clk-fixed-factor.c b/drivers/clk/clk-fixed-factor.c
index b3e66202b942..6f5ce5eb893f 100644
--- a/drivers/clk/clk-fixed-factor.c
+++ b/drivers/clk/clk-fixed-factor.c
@@ -268,14 +268,8 @@  static struct clk_hw *_of_fixed_factor_clk_setup(struct device_node *node)
 
 	hw = __clk_hw_register_fixed_factor(NULL, node, clk_name, NULL, NULL, 0,
 					    0, mult, div, false);
-	if (IS_ERR(hw)) {
-		/*
-		 * Clear OF_POPULATED flag so that clock registration can be
-		 * attempted again from probe function.
-		 */
-		of_node_clear_flag(node, OF_POPULATED);
+	if (IS_ERR(hw))
 		return ERR_CAST(hw);
-	}
 
 	ret = of_clk_add_hw_provider(node, of_clk_hw_simple_get, hw);
 	if (ret) {
@@ -292,7 +286,16 @@  static struct clk_hw *_of_fixed_factor_clk_setup(struct device_node *node)
  */
 void __init of_fixed_factor_clk_setup(struct device_node *node)
 {
-	_of_fixed_factor_clk_setup(node);
+	struct clk_hw *hw;
+
+	hw = _of_fixed_factor_clk_setup(node);
+	if (IS_ERR(hw)) {
+		/*
+		 * Clear OF_POPULATED flag so that clock registration can be
+		 * attempted again from probe function.
+		 */
+		of_node_clear_flag(node, OF_POPULATED);
+	}
 }
 CLK_OF_DECLARE(fixed_factor_clk, "fixed-factor-clock",
 		of_fixed_factor_clk_setup);
diff --git a/drivers/clk/clk-fixed-rate.c b/drivers/clk/clk-fixed-rate.c
index 3481eb8cdeb3..46921cf5b3b2 100644
--- a/drivers/clk/clk-fixed-rate.c
+++ b/drivers/clk/clk-fixed-rate.c
@@ -192,7 +192,16 @@  static struct clk_hw *_of_fixed_clk_setup(struct device_node *node)
  */
 void __init of_fixed_clk_setup(struct device_node *node)
 {
-	_of_fixed_clk_setup(node);
+	struct clk_hw *hw;
+
+	hw = _of_fixed_clk_setup(node);
+	if (IS_ERR(hw)) {
+		/*
+		 * Clear OF_POPULATED flag so that clock registration can be
+		 * attempted again from probe function.
+		 */
+		of_node_clear_flag(node, OF_POPULATED);
+	}
 }
 CLK_OF_DECLARE(fixed_clk, "fixed-clock", of_fixed_clk_setup);