linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] clk: fix parent validation in __clk_set_parent()
@ 2012-07-03 11:12 Rajendra Nayak
  2012-07-05  0:57 ` Prashant Gaikwad
  0 siblings, 1 reply; 3+ messages in thread
From: Rajendra Nayak @ 2012-07-03 11:12 UTC (permalink / raw)
  To: mturquette, mturquette
  Cc: linux-arm-kernel, linux-kernel, mkl, Rajendra Nayak

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>
---
 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 8996f46..46317cb 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)
 
 	old_parent = clk->parent;
 
-	/* find index of new parent clock using cached parent ptrs */
-	if (clk->parents)
-		for (i = 0; i < clk->num_parents; i++)
-			if (clk->parents[i] == parent)
-				break;
-	else
+	if (!clk->parents)
 		clk->parents = kzalloc((sizeof(struct clk*) * clk->num_parents),
 								GFP_KERNEL);
 
 	/*
-	 * find index of new parent clock using string name comparison
-	 * also try to cache the parent to avoid future calls to __clk_lookup
+	 * find index of new parent clock using cached parent ptrs,
+	 * or if not yet cached, use string name comparison and cache
+	 * them now to avoid future calls to __clk_lookup.
 	 */
-	if (i == clk->num_parents)
-		for (i = 0; i < clk->num_parents; i++)
-			if (!strcmp(clk->parent_names[i], parent->name)) {
-				if (clk->parents)
-					clk->parents[i] = __clk_lookup(parent->name);
-				break;
-			}
+	for (i = 0; i < clk->num_parents; i++) {
+		if (clk->parents && clk->parents[i] == parent)
+			break;
+		else if (!strcmp(clk->parent_names[i], parent->name)) {
+			if (clk->parents)
+				clk->parents[i] = __clk_lookup(parent->name);
+			break;
+		}
+	}
 
 	if (i == clk->num_parents) {
 		pr_debug("%s: clock %s is not a possible parent of clock %s\n",
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] clk: fix parent validation in __clk_set_parent()
  2012-07-03 11:12 [PATCH] clk: fix parent validation in __clk_set_parent() Rajendra Nayak
@ 2012-07-05  0:57 ` Prashant Gaikwad
  2012-07-05 19:18   ` Turquette, Mike
  0 siblings, 1 reply; 3+ messages in thread
From: Prashant Gaikwad @ 2012-07-05  0:57 UTC (permalink / raw)
  To: Rajendra Nayak
  Cc: mturquette, mturquette, linux-arm-kernel, linux-kernel, mkl, swarren

On Tuesday 03 July 2012 04:42 PM, Rajendra Nayak wrote:
> 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.

Need this fix for Tegra too.

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] clk: fix parent validation in __clk_set_parent()
  2012-07-05  0:57 ` Prashant Gaikwad
@ 2012-07-05 19:18   ` Turquette, Mike
  0 siblings, 0 replies; 3+ messages in thread
From: Turquette, Mike @ 2012-07-05 19:18 UTC (permalink / raw)
  To: Prashant Gaikwad
  Cc: Rajendra Nayak, linux-arm-kernel, linux-kernel, mkl, swarren

On Wed, Jul 4, 2012 at 5:57 PM, Prashant Gaikwad <pgaikwad@nvidia.com> wrote:
> On Tuesday 03 July 2012 04:42 PM, Rajendra Nayak wrote:
>>
>> 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.
>
>
> Need this fix for Tegra too.
>

Hi Prashant,

You'll find it if you pull the latest clk-next.

Regards,
Mike

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-07-05 19:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-03 11:12 [PATCH] clk: fix parent validation in __clk_set_parent() Rajendra Nayak
2012-07-05  0:57 ` Prashant Gaikwad
2012-07-05 19:18   ` Turquette, Mike

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).