]> Pileus Git - ~andy/linux/commitdiff
clk: only call get_parent if there is one
authorAlex Elder <alex.elder@linaro.org>
Thu, 5 Sep 2013 13:33:24 +0000 (08:33 -0500)
committerMike Turquette <mturquette@linaro.org>
Mon, 9 Sep 2013 21:10:10 +0000 (14:10 -0700)
In __clk_init(), after a clock is mostly initialized, a scan is done
of the orphan clocks to see if the clock being registered is the
parent of any of them.

This code assumes that any clock that provides a get_parent method
actually has at least one parent, and that's not a valid assumption.

As a result, an orphan clock with no parent can return *something*
as the parent index, and that value is blindly used to dereference
the orphan's parent_names[] array (which will be ZERO_SIZE_PTR or
NULL).

Fix this by ensuring get_parent is only called for orphans with at
least one parent.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Mike Turquette <mturquette@linaro.org>
drivers/clk/clk.c

index cc4cb6fd7d83d28997f328ce9df9f6871af104a5..a004769528e68a815293d1832f49e04eec7ca08a 100644 (file)
@@ -1742,7 +1742,7 @@ int __clk_init(struct device *dev, struct clk *clk)
         * this clock
         */
        hlist_for_each_entry_safe(orphan, tmp2, &clk_orphan_list, child_node) {
-               if (orphan->ops->get_parent) {
+               if (orphan->num_parents && orphan->ops->get_parent) {
                        i = orphan->ops->get_parent(orphan->hw);
                        if (!strcmp(clk->name, orphan->parent_names[i]))
                                __clk_reparent(orphan, clk);