diff options
author | Mans Rullgard <mans@mansr.com> | 2015-02-15 13:33:49 +0100 |
---|---|---|
committer | Stephen Boyd <sboyd@codeaurora.org> | 2015-09-17 00:35:18 +0200 |
commit | 9054a31d603ea82c6ed4914170a8708812a16324 (patch) | |
tree | f04390e54f455155eea0975be5cf9e9ef23552b8 | |
parent | clk: tegra: dfll: Properly protect OPP list (diff) | |
download | linux-9054a31d603ea82c6ed4914170a8708812a16324.tar.xz linux-9054a31d603ea82c6ed4914170a8708812a16324.zip |
clk: check for invalid parent index of orphans in __clk_init()
If a mux clock is initialised (by hardware or firmware) with an
invalid parent, its ->get_parent() can return an out of range
index. For example, the generic mux clock attempts to return
-EINVAL, which due to the u8 return type ends up a rather large
number. Using this index with the parent_names[] array results
in an invalid pointer and (usually) a crash in the following
strcmp().
This patch adds a check for the parent index being in range,
ignoring clocks reporting invalid values.
Signed-off-by: Mans Rullgard <mans@mansr.com>
Tested-by: Rhyland Klein <rklein@nvidia.com>
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
-rw-r--r-- | drivers/clk/clk.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 43e2c3ad6c31..0ebcf449778a 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -2437,7 +2437,8 @@ static int __clk_init(struct device *dev, struct clk *clk_user) hlist_for_each_entry_safe(orphan, tmp2, &clk_orphan_list, child_node) { if (orphan->num_parents && orphan->ops->get_parent) { i = orphan->ops->get_parent(orphan->hw); - if (!strcmp(core->name, orphan->parent_names[i])) + if (i >= 0 && i < orphan->num_parents && + !strcmp(core->name, orphan->parent_names[i])) clk_core_reparent(orphan, core); continue; } |