diff mbox series

[01/42] clk: at91: sama7g5: check __clk_get_hw() argument for errors

Message ID 20230727053156.13587-2-claudiu.beznea@tuxon.dev (mailing list archive)
State New, archived
Headers show
Series clk: at91: add support for parent_data and parent_hw (take #2) | expand

Commit Message

Claudiu Beznea July 27, 2023, 5:31 a.m. UTC
__clk_get_hw() argument in sama7g5 is obtained using
of_clk_get_by_name() which might return error. Passing an error casted
pointer to __clk_get_hw() may lead to crashes. Thus, check the pointer
for errors before passing it to __clk_get_hw().

Fixes: de3383e993a5 ("clk: at91: sama7g5: switch to parent_hw and parent_data")
Signed-off-by: Claudiu Beznea <claudiu.beznea@tuxon.dev>
---
 drivers/clk/at91/sama7g5.c | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/drivers/clk/at91/sama7g5.c b/drivers/clk/at91/sama7g5.c
index 91b5c6f14819..16e458be8304 100644
--- a/drivers/clk/at91/sama7g5.c
+++ b/drivers/clk/at91/sama7g5.c
@@ -988,14 +988,27 @@  static void __init sama7g5_pmc_setup(struct device_node *np)
 	struct clk_hw *td_slck_hw, *md_slck_hw;
 	static struct clk_parent_data parent_data;
 	struct clk_hw *parent_hws[10];
+	struct clk *clk;
 	bool bypass;
 	int i, j;
 
-	td_slck_hw = __clk_get_hw(of_clk_get_by_name(np, "td_slck"));
-	md_slck_hw = __clk_get_hw(of_clk_get_by_name(np, "md_slck"));
-	main_xtal_hw = __clk_get_hw(of_clk_get_by_name(np, main_xtal_name));
-
-	if (!td_slck_hw || !md_slck_hw || !main_xtal_hw)
+	clk = of_clk_get_by_name(np, "td_slck");
+	if (IS_ERR(clk))
+		return;
+	td_slck_hw = __clk_get_hw(clk);
+	if (!td_slck_hw)
+		return;
+	clk = of_clk_get_by_name(np, "md_slck");
+	if (IS_ERR(clk))
+		return;
+	md_slck_hw = __clk_get_hw(clk);
+	if (!md_slck_hw)
+		return;
+	clk = of_clk_get_by_name(np, main_xtal_name);
+	if (IS_ERR(clk))
+		return;
+	main_xtal_hw = __clk_get_hw(clk);
+	if (!main_xtal_hw)
 		return;
 
 	regmap = device_node_to_regmap(np);