Skip to content

Commit 9e85a6f

Browse files
committed
Merge tag 'clk-fixes-for-linus' of git://git.linaro.org/people/mturquette/linux
Pull fix to common clk framework from Michael Turquette: "The previous set of common clk fixes for -rc5 left an uninitialized int which could lead to bad array indexing when switching clock parents. The issue is fixed with a trivial change to the code flow in __clk_set_parent." * tag 'clk-fixes-for-linus' of git://git.linaro.org/people/mturquette/linux: clk: fix parent validation in __clk_set_parent()
2 parents 6c8addc + 863b132 commit 9e85a6f

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

drivers/clk/clk.c

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,26 +1067,24 @@ static int __clk_set_parent(struct clk *clk, struct clk *parent)
10671067

10681068
old_parent = clk->parent;
10691069

1070-
/* find index of new parent clock using cached parent ptrs */
1071-
if (clk->parents)
1072-
for (i = 0; i < clk->num_parents; i++)
1073-
if (clk->parents[i] == parent)
1074-
break;
1075-
else
1070+
if (!clk->parents)
10761071
clk->parents = kzalloc((sizeof(struct clk*) * clk->num_parents),
10771072
GFP_KERNEL);
10781073

10791074
/*
1080-
* find index of new parent clock using string name comparison
1081-
* also try to cache the parent to avoid future calls to __clk_lookup
1075+
* find index of new parent clock using cached parent ptrs,
1076+
* or if not yet cached, use string name comparison and cache
1077+
* them now to avoid future calls to __clk_lookup.
10821078
*/
1083-
if (i == clk->num_parents)
1084-
for (i = 0; i < clk->num_parents; i++)
1085-
if (!strcmp(clk->parent_names[i], parent->name)) {
1086-
if (clk->parents)
1087-
clk->parents[i] = __clk_lookup(parent->name);
1088-
break;
1089-
}
1079+
for (i = 0; i < clk->num_parents; i++) {
1080+
if (clk->parents && clk->parents[i] == parent)
1081+
break;
1082+
else if (!strcmp(clk->parent_names[i], parent->name)) {
1083+
if (clk->parents)
1084+
clk->parents[i] = __clk_lookup(parent->name);
1085+
break;
1086+
}
1087+
}
10901088

10911089
if (i == clk->num_parents) {
10921090
pr_debug("%s: clock %s is not a possible parent of clock %s\n",

0 commit comments

Comments
 (0)