mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <>
Cc: Ahmad Fatoum <>
Subject: [PATCH master 2/2] clk: composite: fix possible NULL pointer dereference
Date: Mon,  7 Mar 2022 18:01:06 +0100	[thread overview]
Message-ID: <> (raw)
In-Reply-To: <>

A composite clock is at most composed of a mux, a divider and a gate,
but it may lack one or two of these components. In that case, a NULL
pointer is passed, so we need to deal with this case.

Fixes: 8b0ca7a885ea ("clk: composite: add clk_hw registration functions")
Signed-off-by: Ahmad Fatoum <>
 drivers/clk/clk-composite.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
index 63056b769647..4ebdd399b44b 100644
--- a/drivers/clk/clk-composite.c
+++ b/drivers/clk/clk-composite.c
@@ -181,9 +181,13 @@ struct clk_hw *clk_hw_register_composite(struct device_d *dev,
 		unsigned long flags)
 	struct clk *clk;
-	mux_hw->clk.ops = mux_ops;
-	rate_hw->clk.ops = rate_ops;
-	gate_hw->clk.ops = gate_ops;
+	if (mux_hw)
+		mux_hw->clk.ops = mux_ops;
+	if (rate_hw)
+		rate_hw->clk.ops = rate_ops;
+	if (gate_hw)
+		gate_hw->clk.ops = gate_ops;
 	parent_names = memdup_array(parent_names, num_parents);
 	if (!parent_names)

barebox mailing list

  reply	other threads:[~2022-03-07 17:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-07 17:01 [PATCH master 1/2] clk: harden NULL handling in clk_hw_to_clk/clk_to_clk_hw Ahmad Fatoum
2022-03-07 17:01 ` Ahmad Fatoum [this message]
2022-03-08  8:19 ` Sascha Hauer

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:

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

  git send-email \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox