diff options
author | Rajendra Nayak <rnayak@ti.com> | 2012-07-03 02:41:41 -0400 |
---|---|---|
committer | Mike Turquette <mturquette@linaro.org> | 2012-07-03 15:05:14 -0400 |
commit | 863b13271f1608ab3af6f7a371047d9a66693e38 (patch) | |
tree | 990c7445eff9b8da1e52eeca07101c13d928c920 /drivers/clk/clk.c | |
parent | 6887a4131da3adaab011613776d865f4bcfb5678 (diff) |
clk: fix parent validation in __clk_set_parent()
The below commit introduced a bug in __clk_set_parent()
which could cause it to *skip* the parent validation
which makes sure the parent passed to the api is a valid
one.
commit 7975059db572eb47f0fb272a62afeae272a4b209
Author: Rajendra Nayak <rnayak@ti.com>
Date: Wed Jun 6 14:41:31 2012 +0530
clk: Allow late cache allocation for clk->parents
This was identified by the following compiler warning..
drivers/clk/clk.c: In function '__clk_set_parent':
drivers/clk/clk.c:1083:5: warning: 'i' may be used uninitialized in this function [-Wuninitialized]
.. as reported by Marc Kleine-Budde.
There were various options discussed on how to fix this, one
being initing 'i' to clk->num_parents, but the below approach
was found to be more appropriate as it also makes the 'parent
validation' code simpler to read.
Reported-by: Marc Kleine-Budde <mkl@pengutronix.de>
Signed-off-by: Rajendra Nayak <rnayak@ti.com>
Signed-off-by: Mike Turquette <mturquette@linaro.org>
Cc: stable@kernel.org
Diffstat (limited to 'drivers/clk/clk.c')
-rw-r--r-- | drivers/clk/clk.c | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index dcbe05616090..9a1eb0cfa95f 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c | |||
@@ -1067,26 +1067,24 @@ static int __clk_set_parent(struct clk *clk, struct clk *parent) | |||
1067 | 1067 | ||
1068 | old_parent = clk->parent; | 1068 | old_parent = clk->parent; |
1069 | 1069 | ||
1070 | /* find index of new parent clock using cached parent ptrs */ | 1070 | if (!clk->parents) |
1071 | if (clk->parents) | ||
1072 | for (i = 0; i < clk->num_parents; i++) | ||
1073 | if (clk->parents[i] == parent) | ||
1074 | break; | ||
1075 | else | ||
1076 | clk->parents = kzalloc((sizeof(struct clk*) * clk->num_parents), | 1071 | clk->parents = kzalloc((sizeof(struct clk*) * clk->num_parents), |
1077 | GFP_KERNEL); | 1072 | GFP_KERNEL); |
1078 | 1073 | ||
1079 | /* | 1074 | /* |
1080 | * find index of new parent clock using string name comparison | 1075 | * find index of new parent clock using cached parent ptrs, |
1081 | * also try to cache the parent to avoid future calls to __clk_lookup | 1076 | * or if not yet cached, use string name comparison and cache |
1077 | * them now to avoid future calls to __clk_lookup. | ||
1082 | */ | 1078 | */ |
1083 | if (i == clk->num_parents) | 1079 | for (i = 0; i < clk->num_parents; i++) { |
1084 | for (i = 0; i < clk->num_parents; i++) | 1080 | if (clk->parents && clk->parents[i] == parent) |
1085 | if (!strcmp(clk->parent_names[i], parent->name)) { | 1081 | break; |
1086 | if (clk->parents) | 1082 | else if (!strcmp(clk->parent_names[i], parent->name)) { |
1087 | clk->parents[i] = __clk_lookup(parent->name); | 1083 | if (clk->parents) |
1088 | break; | 1084 | clk->parents[i] = __clk_lookup(parent->name); |
1089 | } | 1085 | break; |
1086 | } | ||
1087 | } | ||
1090 | 1088 | ||
1091 | if (i == clk->num_parents) { | 1089 | if (i == clk->num_parents) { |
1092 | pr_debug("%s: clock %s is not a possible parent of clock %s\n", | 1090 | pr_debug("%s: clock %s is not a possible parent of clock %s\n", |