clk: qcom: Fix possible NULL pointer dereferences

Add checks to properly handle and fix possible NULL pointer
dereferences and avoid usage of uninitialized variables.

Change-Id: I8c8fe1aa648e3f9fd6d7adf0ba55dc78d86ae25f
Signed-off-by: Jagadeesh Kona <jkona@codeaurora.org>
This commit is contained in:
Jagadeesh Kona
2020-07-28 13:27:50 +05:30
parent e3e20132c3
commit 070f2bf811
3 changed files with 13 additions and 2 deletions

View File

@ -918,8 +918,13 @@ static int alpha_pll_huayra_determine_rate(struct clk_hw *hw,
{
unsigned long rrate, prate;
u32 l, a;
struct clk_hw *parent_hw;
prate = clk_hw_get_rate(clk_hw_get_parent(hw));
parent_hw = clk_hw_get_parent(hw);
if (!parent_hw)
return -EINVAL;
prate = clk_hw_get_rate(parent_hw);
rrate = alpha_huayra_pll_round_rate(req->rate, prate, &l, &a);
req->best_parent_hw = clk_hw_get_parent(hw);

View File

@ -1336,6 +1336,8 @@ static int clk_gfx3d_src_determine_rate(struct clk_hw *hw,
int ret;
xo = clk_hw_get_parent_by_index(hw, 0);
if (!xo)
return -EINVAL;
if (req->rate == clk_hw_get_rate(xo)) {
req->best_parent_hw = xo;
req->best_parent_rate = req->rate;
@ -1343,7 +1345,9 @@ static int clk_gfx3d_src_determine_rate(struct clk_hw *hw,
}
f = qcom_find_freq(rcg->freq_tbl, req->rate);
if (!f || (req->rate != f->freq))
if (!f)
return -EINVAL;
else if (req->rate != f->freq)
req->rate = f->freq;
/* Indexes of source from the parent map */

View File

@ -459,6 +459,8 @@ static int qcom_cpufreq_hw_read_lut(struct platform_device *pdev,
base_freq = c->reg_bases[REG_FREQ_LUT_TABLE];
base_volt = c->reg_bases[REG_VOLT_LUT_TABLE];
prev_cc = 0;
for (i = 0; i < lut_max_entries; i++) {
data = readl_relaxed(base_freq + i * lut_row_size);
src = (data & GENMASK(31, 30)) >> 30;