Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fb03af1d authored by Vivek Aknurwar's avatar Vivek Aknurwar
Browse files

clk: qcom: clk-rcg2: Fix possible dereference of clk parent for dfs clocks



Fix possible dereference of clk parent while populating dfs clocks.

Change-Id: I797c499fe3ab57effb16c65f89365da9e5279995
Signed-off-by: default avatarVivek Aknurwar <viveka@codeaurora.org>
parent bc477961
Loading
Loading
Loading
Loading
+12 −6
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright (c) 2013, 2016-2019, The Linux Foundation. All rights reserved.
 * Copyright (c) 2013, 2016-2020, The Linux Foundation. All rights reserved.
 */

#include <linux/kernel.h>
@@ -1435,7 +1435,7 @@ const struct clk_ops clk_rcg2_shared_ops = {
EXPORT_SYMBOL_GPL(clk_rcg2_shared_ops);

/* Common APIs to be used for DFS based RCGR */
static void clk_rcg2_dfs_populate_freq(struct clk_hw *hw, unsigned int l,
static int clk_rcg2_dfs_populate_freq(struct clk_hw *hw, unsigned int l,
				       struct freq_tbl *f)
{
	struct clk_rcg2 *rcg = to_clk_rcg2(hw);
@@ -1462,6 +1462,8 @@ static void clk_rcg2_dfs_populate_freq(struct clk_hw *hw, unsigned int l,
		if (src == rcg->parent_map[i].cfg) {
			f->src = rcg->parent_map[i].src;
			p = clk_hw_get_parent_by_index(&rcg->clkr.hw, i);
			if (!p)
				return -EINVAL;
			prate = clk_hw_get_rate(p);
		}
	}
@@ -1482,12 +1484,13 @@ static void clk_rcg2_dfs_populate_freq(struct clk_hw *hw, unsigned int l,
	}

	f->freq = calc_rate(prate, f->m, f->n, mode, f->pre_div);
	return 0;
}

static int clk_rcg2_dfs_populate_freq_table(struct clk_rcg2 *rcg)
{
	struct freq_tbl *freq_tbl;
	int i;
	int i, ret;

	/* Allocate space for 1 extra since table is NULL terminated */
	freq_tbl = kcalloc(MAX_PERF_LEVEL + 1, sizeof(*freq_tbl), GFP_KERNEL);
@@ -1495,10 +1498,13 @@ static int clk_rcg2_dfs_populate_freq_table(struct clk_rcg2 *rcg)
		return -ENOMEM;
	rcg->freq_tbl = freq_tbl;

	for (i = 0; i < MAX_PERF_LEVEL; i++)
	for (i = 0; i < MAX_PERF_LEVEL; i++) {
		ret =
		clk_rcg2_dfs_populate_freq(&rcg->clkr.hw, i, freq_tbl + i);

	return 0;
		if (ret)
			return ret;
	}
	return ret;
}

static int clk_rcg2_dfs_determine_rate(struct clk_hw *hw,