Skip to contentSkip to conversation

clk: only call get_parent if there is one

PATCH New Alex Elder 2 participants 2 messages Sep 5, 2013 – Sep 6, 2013 Common clk

lore
Share & tools
lore

Alex Elder

author
#0 lore raw

PATCH 1/1 clk: only call get_parent if there is one

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.

---
 drivers/clk/clk.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/clk/clk.c +1 -1
index 54a191c..ea8ff15 100644
@@ -1628,7 +1628,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);
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH 1/1 clk: only call get_parent if there is one

Quoting Alex Elder (2013-09-05 06:33:24)

Quoted 12 lines

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).

Quoted 4 lines

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

Thanks for the fix Alex. I'll take this in towards 3.13.

Regards,
Mike

Quoted 19 lines
---
 drivers/clk/clk.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/clk/clk.c +1 -1
index 54a191c..ea8ff15 100644
@@ -1628,7 +1628,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);
Signature · 1 line
1.7.9.5