diff mbox series

[07/16] clk: qcom: clk-krait: add hw_parent check for div2_round_rate

Message ID 20220313190419.2207-8-ansuelsmth@gmail.com (mailing list archive)
State Superseded
Headers show
Series Modernize rest of the krait drivers | expand

Commit Message

Christian Marangi March 13, 2022, 7:04 p.m. UTC
Check if hw_parent is present before calculating the round_rate to
prevent kernel panic.

Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
---
 drivers/clk/qcom/clk-krait.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

Stephen Boyd March 15, 2022, 10:43 p.m. UTC | #1
Quoting Ansuel Smith (2022-03-13 12:04:10)
> Check if hw_parent is present before calculating the round_rate to
> prevent kernel panic.
> 
> Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
> ---
>  drivers/clk/qcom/clk-krait.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/clk/qcom/clk-krait.c b/drivers/clk/qcom/clk-krait.c
> index e447fcc3806d..d8af281eba0e 100644
> --- a/drivers/clk/qcom/clk-krait.c
> +++ b/drivers/clk/qcom/clk-krait.c
> @@ -80,7 +80,12 @@ EXPORT_SYMBOL_GPL(krait_mux_clk_ops);
>  static long krait_div2_round_rate(struct clk_hw *hw, unsigned long rate,
>                                   unsigned long *parent_rate)
>  {
> -       *parent_rate = clk_hw_round_rate(clk_hw_get_parent(hw), rate * 2);
> +       struct clk_hw *hw_parent = clk_hw_get_parent(hw);
> +
> +       if (!hw_parent)
> +               return -1;

Use -EINVAL or some proper error code, not just -1

> +
> +       *parent_rate = clk_hw_round_rate(hw_parent, rate * 2);
>         return DIV_ROUND_UP(*parent_rate, 2);
>  }
>  
> -- 
> 2.34.1
>
diff mbox series

Patch

diff --git a/drivers/clk/qcom/clk-krait.c b/drivers/clk/qcom/clk-krait.c
index e447fcc3806d..d8af281eba0e 100644
--- a/drivers/clk/qcom/clk-krait.c
+++ b/drivers/clk/qcom/clk-krait.c
@@ -80,7 +80,12 @@  EXPORT_SYMBOL_GPL(krait_mux_clk_ops);
 static long krait_div2_round_rate(struct clk_hw *hw, unsigned long rate,
 				  unsigned long *parent_rate)
 {
-	*parent_rate = clk_hw_round_rate(clk_hw_get_parent(hw), rate * 2);
+	struct clk_hw *hw_parent = clk_hw_get_parent(hw);
+
+	if (!hw_parent)
+		return -1;
+
+	*parent_rate = clk_hw_round_rate(hw_parent, rate * 2);
 	return DIV_ROUND_UP(*parent_rate, 2);
 }