aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/clk/clk.c
diff options
context:
space:
mode:
authorTomasz Figa <tomasz.figa@gmail.com>2013-09-28 20:37:14 -0400
committerMike Turquette <mturquette@linaro.org>2013-10-01 21:40:16 -0400
commitf1c8b2edf916b5be9dc29e98989a5eaff3c6e75b (patch)
treee46e0af10ea370a78ed7ed33c615e68988d2f3e1 /drivers/clk/clk.c
parent15c03dd4859ab16f9212238f29dd315654aa94f6 (diff)
clk: Add error handling to clk_fetch_parent_index()
There are at least two different error cases that can happen in clk_fetch_parent_index() function: - allocation failure, - parent clock lookup failure, however it returns only an u8, which is supposed to contain parent clock index. This patch modified the function to return full int instead allowing positive clock indices and negative error codes to be returned. All users of this function are adjusted as well to handle the return value correctly. Signed-off-by: Tomasz Figa <tomasz.figa@gmail.com> Signed-off-by: Mike Turquette <mturquette@linaro.org>
Diffstat (limited to 'drivers/clk/clk.c')
-rw-r--r--drivers/clk/clk.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index a004769528e6..9e0a8372f59c 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -1080,13 +1080,16 @@ unsigned long clk_get_rate(struct clk *clk)
1080} 1080}
1081EXPORT_SYMBOL_GPL(clk_get_rate); 1081EXPORT_SYMBOL_GPL(clk_get_rate);
1082 1082
1083static u8 clk_fetch_parent_index(struct clk *clk, struct clk *parent) 1083static int clk_fetch_parent_index(struct clk *clk, struct clk *parent)
1084{ 1084{
1085 u8 i; 1085 int i;
1086 1086
1087 if (!clk->parents) 1087 if (!clk->parents) {
1088 clk->parents = kzalloc((sizeof(struct clk*) * clk->num_parents), 1088 clk->parents = kzalloc((sizeof(struct clk*) * clk->num_parents),
1089 GFP_KERNEL); 1089 GFP_KERNEL);
1090 if (!clk->parents)
1091 return -ENOMEM;
1092 }
1090 1093
1091 /* 1094 /*
1092 * find index of new parent clock using cached parent ptrs, 1095 * find index of new parent clock using cached parent ptrs,
@@ -1095,15 +1098,15 @@ static u8 clk_fetch_parent_index(struct clk *clk, struct clk *parent)
1095 */ 1098 */
1096 for (i = 0; i < clk->num_parents; i++) { 1099 for (i = 0; i < clk->num_parents; i++) {
1097 if (clk->parents && clk->parents[i] == parent) 1100 if (clk->parents && clk->parents[i] == parent)
1098 break; 1101 return i;
1099 else if (!strcmp(clk->parent_names[i], parent->name)) { 1102 else if (!strcmp(clk->parent_names[i], parent->name)) {
1100 if (clk->parents) 1103 if (clk->parents)
1101 clk->parents[i] = __clk_lookup(parent->name); 1104 clk->parents[i] = __clk_lookup(parent->name);
1102 break; 1105 return i;
1103 } 1106 }
1104 } 1107 }
1105 1108
1106 return i; 1109 return -EINVAL;
1107} 1110}
1108 1111
1109static void clk_reparent(struct clk *clk, struct clk *new_parent) 1112static void clk_reparent(struct clk *clk, struct clk *new_parent)
@@ -1265,7 +1268,7 @@ static struct clk *clk_calc_new_rates(struct clk *clk, unsigned long rate)
1265 struct clk *old_parent, *parent; 1268 struct clk *old_parent, *parent;
1266 unsigned long best_parent_rate = 0; 1269 unsigned long best_parent_rate = 0;
1267 unsigned long new_rate; 1270 unsigned long new_rate;
1268 u8 p_index = 0; 1271 int p_index = 0;
1269 1272
1270 /* sanity */ 1273 /* sanity */
1271 if (IS_ERR_OR_NULL(clk)) 1274 if (IS_ERR_OR_NULL(clk))
@@ -1306,7 +1309,7 @@ static struct clk *clk_calc_new_rates(struct clk *clk, unsigned long rate)
1306 /* try finding the new parent index */ 1309 /* try finding the new parent index */
1307 if (parent) { 1310 if (parent) {
1308 p_index = clk_fetch_parent_index(clk, parent); 1311 p_index = clk_fetch_parent_index(clk, parent);
1309 if (p_index == clk->num_parents) { 1312 if (p_index < 0) {
1310 pr_debug("%s: clk %s can not be parent of clk %s\n", 1313 pr_debug("%s: clk %s can not be parent of clk %s\n",
1311 __func__, parent->name, clk->name); 1314 __func__, parent->name, clk->name);
1312 return NULL; 1315 return NULL;
@@ -1568,7 +1571,7 @@ void __clk_reparent(struct clk *clk, struct clk *new_parent)
1568int clk_set_parent(struct clk *clk, struct clk *parent) 1571int clk_set_parent(struct clk *clk, struct clk *parent)
1569{ 1572{
1570 int ret = 0; 1573 int ret = 0;
1571 u8 p_index = 0; 1574 int p_index = 0;
1572 unsigned long p_rate = 0; 1575 unsigned long p_rate = 0;
1573 1576
1574 if (!clk) 1577 if (!clk)
@@ -1597,10 +1600,10 @@ int clk_set_parent(struct clk *clk, struct clk *parent)
1597 if (parent) { 1600 if (parent) {
1598 p_index = clk_fetch_parent_index(clk, parent); 1601 p_index = clk_fetch_parent_index(clk, parent);
1599 p_rate = parent->rate; 1602 p_rate = parent->rate;
1600 if (p_index == clk->num_parents) { 1603 if (p_index < 0) {
1601 pr_debug("%s: clk %s can not be parent of clk %s\n", 1604 pr_debug("%s: clk %s can not be parent of clk %s\n",
1602 __func__, parent->name, clk->name); 1605 __func__, parent->name, clk->name);
1603 ret = -EINVAL; 1606 ret = p_index;
1604 goto out; 1607 goto out;
1605 } 1608 }
1606 } 1609 }