From bca835dfe301c92e012e72660587ccf4995fea57 Mon Sep 17 00:00:00 2001 From: Mike Tipton Date: Wed, 5 May 2021 11:41:19 -0700 Subject: [PATCH] clk: qcom: Fix NULL deref when deteremine_rate called on orphan Some of the determine_rate callbacks rely on the clock parent to determine the rate. This isn't possible if the clock is orphaned without a parent. So return an error in this case instead of dereferencing NULL. Change-Id: Ifaa8f2a85a8f8d4e37895c0b130e4eaefb0374cb Signed-off-by: Mike Tipton --- drivers/clk/qcom/clk-rcg2.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/clk/qcom/clk-rcg2.c b/drivers/clk/qcom/clk-rcg2.c index 1007ce58e8b8..1d6bd7705050 100644 --- a/drivers/clk/qcom/clk-rcg2.c +++ b/drivers/clk/qcom/clk-rcg2.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * Copyright (c) 2013, 2016-2020, The Linux Foundation. All rights reserved. + * Copyright (c) 2013, 2016-2018, 2020-2021, The Linux Foundation. All rights reserved. */ #include @@ -950,10 +950,11 @@ static int clk_byte2_determine_rate(struct clk_hw *hw, struct clk_hw *p; unsigned long rate = req->rate; - if (rate == 0) + p = req->best_parent_hw; + + if (!p || rate == 0) return -EINVAL; - p = req->best_parent_hw; req->best_parent_rate = parent_rate = clk_hw_round_rate(p, rate); div = DIV_ROUND_UP((2 * parent_rate), rate) - 1; @@ -1030,6 +1031,9 @@ static int clk_pixel_determine_rate(struct clk_hw *hw, int delta = 100000; const struct frac_entry *frac = frac_table_pixel; + if (!req->best_parent_hw) + return -EINVAL; + for (; frac->num; frac++) { request = (req->rate * frac->den) / frac->num;