clk: imx: gate2: Add locking in is_enabled op
authorAbel Vesa <abel.vesa@nxp.com>
Wed, 28 Oct 2020 12:59:02 +0000 (14:59 +0200)
committerShawn Guo <shawnguo@kernel.org>
Mon, 2 Nov 2020 23:55:41 +0000 (07:55 +0800)
Protect against enabling/disabling the gate while we're
checking if it is enabled.

Signed-off-by: Abel Vesa <abel.vesa@nxp.com>
Reviewed-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Shawn Guo <shawnguo@kernel.org>
drivers/clk/imx/clk-gate2.c

index 7e4b5e82de7fc9e073846d45fa437abfb8a16005..480a184207d56d02eeb96f03e2e1ab60b03fa10c 100644 (file)
@@ -101,9 +101,17 @@ static int clk_gate2_reg_is_enabled(void __iomem *reg, u8 bit_idx,
 static int clk_gate2_is_enabled(struct clk_hw *hw)
 {
        struct clk_gate2 *gate = to_clk_gate2(hw);
+       unsigned long flags;
+       int ret = 0;
+
+       spin_lock_irqsave(gate->lock, flags);
 
-       return clk_gate2_reg_is_enabled(gate->reg, gate->bit_idx,
+       ret = clk_gate2_reg_is_enabled(gate->reg, gate->bit_idx,
                                        gate->cgr_val, gate->cgr_mask);
+
+       spin_unlock_irqrestore(gate->lock, flags);
+
+       return ret;
 }
 
 static void clk_gate2_disable_unused(struct clk_hw *hw)