mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Bastian Krause <bst@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>,
	Bastian Krause <bst@pengutronix.de>
Subject: [PATCH v2] clk: handle NULL args in clk_{g,s}et_parent()
Date: Wed, 11 May 2022 14:31:39 +0200	[thread overview]
Message-ID: <20220511123139.2767034-1-bst@pengutronix.de> (raw)

NULL struct clk pointers should be treated just as the Linux kernel clk
driver does [1]. The reasoning should also apply to the parent clk
argument.

A NULL struct clk pointer can happen for example on the Freescale i.MX6
SABRE Smart Device Board if CONFIG_DRIVER_VIDEO_IMX_IPUV3 is disabled,
leading to assigned-clocks IMX6QDL_CLK_LDB_DI0_SEL and
IMX6QDL_CLK_LDB_DI1_SEL [2] being unavailable. Without this patch, the
board hangs while setting those assigned clock configurations since [3].

[1] 89ac8d7ae1cd ("clk: handle NULL struct clk gracefully")
[2] dts/src/arm/imx6qdl-sabresd.dtsi
[3] f5eb5fddb4 ("clk: fix of clk set defaults when dev is a clk provider")

Signed-off-by: Bastian Krause <bst@pengutronix.de>
---
Changes since (implicit) v1:
- make clk_get_parent(NULL) return NULL
- undo shifting call to clk_get_parent() in clk_set_parent()
---
 drivers/clk/clk.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 8e317b4b05..52e309e877 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -232,6 +232,9 @@ int clk_set_parent(struct clk *clk, struct clk *newparent)
 	int i, ret;
 	struct clk *curparent = clk_get_parent(clk);
 
+	if (!clk || !newparent)
+		return 0;
+
 	if (IS_ERR(clk))
 		return PTR_ERR(clk);
 	if (IS_ERR(newparent))
@@ -287,7 +290,7 @@ struct clk *clk_get_parent(struct clk *clk)
 	struct clk_hw *hw;
 	int idx;
 
-	if (IS_ERR(clk))
+	if (IS_ERR_OR_NULL(clk))
 		return clk;
 
 	if (!clk->num_parents)
-- 
2.30.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


             reply	other threads:[~2022-05-11 12:33 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-11 12:31 Bastian Krause [this message]
2022-05-11 12:46 ` Ahmad Fatoum

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220511123139.2767034-1-bst@pengutronix.de \
    --to=bst@pengutronix.de \
    --cc=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --subject='Re: [PATCH v2] clk: handle NULL args in clk_{g,s}et_parent()' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox