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 <mdtipton@codeaurora.org>
This commit is contained in:
Mike Tipton 2021-05-05 11:41:19 -07:00 committed by Mike Tipton
parent 5031c00a34
commit bca835dfe3

View File

@ -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 <linux/kernel.h>
@ -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;