[PATCH master 2/2] clk: composite: fix possible NULL pointer dereference

Ahmad Fatoum a.fatoum at pengutronix.de
Mon Mar 7 09:01:06 PST 2022


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 <a.fatoum at pengutronix.de>
---
 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)
-- 
2.30.2




More information about the barebox mailing list