From f76ac178ee5390ed815b6a561bb913cca16aae2b Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Mon, 7 Mar 2022 18:01:06 +0100 Subject: clk: composite: fix possible NULL pointer dereference 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 Link: https://lore.barebox.org/20220307170106.3937198-2-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer --- 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 63056b7696..4ebdd399b4 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) -- cgit v1.2.3