* [PATCH 1/1] arm: mxc: utilise usecount field in clock operations
@ 2010-04-22 20:30 Amit Kucheria
2010-04-22 23:00 ` Tim Gardner
0 siblings, 1 reply; 3+ messages in thread
From: Amit Kucheria @ 2010-04-22 20:30 UTC (permalink / raw)
To: linux-arm-kernel
From: Amit Kucheria <amit.kucheria@canonical.com>
This patch fixes the clock refcounting when reparenting is used.
Sascha just pointed out a good explanation of refcounting here:
http://www.spinics.net/lists/arm-kernel/msg85879.html
Signed-off-by: Amit Kucheria <amit.kucheria@canonical.com>
---
arch/arm/plat-mxc/clock.c | 34 ++++++++++++++++++++++------------
1 files changed, 22 insertions(+), 12 deletions(-)
diff --git a/arch/arm/plat-mxc/clock.c b/arch/arm/plat-mxc/clock.c
index 323ff8c..14781cc 100644
--- a/arch/arm/plat-mxc/clock.c
+++ b/arch/arm/plat-mxc/clock.c
@@ -50,15 +50,16 @@ static DEFINE_MUTEX(clocks_mutex);
static void __clk_disable(struct clk *clk)
{
- if (clk == NULL || IS_ERR(clk))
+ WARN_ON(!clk->usecount);
+ if (clk == NULL || IS_ERR(clk) || !clk->usecount)
return;
- __clk_disable(clk->parent);
- __clk_disable(clk->secondary);
-
- WARN_ON(!clk->usecount);
- if (!(--clk->usecount) && clk->disable)
- clk->disable(clk);
+ if (!(--clk->usecount)) {
+ if (clk->disable)
+ clk->disable(clk);
+ __clk_disable(clk->parent);
+ __clk_disable(clk->secondary);
+ }
}
static int __clk_enable(struct clk *clk)
@@ -66,12 +67,13 @@ static int __clk_enable(struct clk *clk)
if (clk == NULL || IS_ERR(clk))
return -EINVAL;
- __clk_enable(clk->parent);
- __clk_enable(clk->secondary);
-
- if (clk->usecount++ == 0 && clk->enable)
- clk->enable(clk);
+ if (clk->usecount++ == 0) {
+ __clk_enable(clk->parent);
+ __clk_enable(clk->secondary);
+ if (clk->enable)
+ clk->enable(clk);
+ }
return 0;
}
@@ -160,17 +162,25 @@ EXPORT_SYMBOL(clk_set_rate);
int clk_set_parent(struct clk *clk, struct clk *parent)
{
int ret = -EINVAL;
+ struct clk *prev_parent = clk->parent;
if (clk == NULL || IS_ERR(clk) || parent == NULL ||
IS_ERR(parent) || clk->set_parent == NULL)
return ret;
+ if (clk->usecount != 0)
+ clk_enable(parent);
+
mutex_lock(&clocks_mutex);
ret = clk->set_parent(clk, parent);
if (ret == 0)
clk->parent = parent;
+
mutex_unlock(&clocks_mutex);
+ if (clk->usecount != 0)
+ clk_disable(prev_parent);
+
return ret;
}
EXPORT_SYMBOL(clk_set_parent);
--
1.7.0.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 1/1] arm: mxc: utilise usecount field in clock operations
2010-04-22 20:30 [PATCH 1/1] arm: mxc: utilise usecount field in clock operations Amit Kucheria
@ 2010-04-22 23:00 ` Tim Gardner
2010-05-28 8:29 ` Amit Kucheria
0 siblings, 1 reply; 3+ messages in thread
From: Tim Gardner @ 2010-04-22 23:00 UTC (permalink / raw)
To: linux-arm-kernel
On 04/22/2010 02:30 PM, Amit Kucheria wrote:
> From: Amit Kucheria<amit.kucheria@canonical.com>
>
> This patch fixes the clock refcounting when reparenting is used.
>
> Sascha just pointed out a good explanation of refcounting here:
> http://www.spinics.net/lists/arm-kernel/msg85879.html
>
> Signed-off-by: Amit Kucheria<amit.kucheria@canonical.com>
> ---
> arch/arm/plat-mxc/clock.c | 34 ++++++++++++++++++++++------------
> 1 files changed, 22 insertions(+), 12 deletions(-)
>
> diff --git a/arch/arm/plat-mxc/clock.c b/arch/arm/plat-mxc/clock.c
> index 323ff8c..14781cc 100644
> --- a/arch/arm/plat-mxc/clock.c
> +++ b/arch/arm/plat-mxc/clock.c
> @@ -50,15 +50,16 @@ static DEFINE_MUTEX(clocks_mutex);
>
> static void __clk_disable(struct clk *clk)
> {
> - if (clk == NULL || IS_ERR(clk))
> + WARN_ON(!clk->usecount);
> + if (clk == NULL || IS_ERR(clk) || !clk->usecount)
> return;
>
The clk==NULL check seem superfluous if WARN_ON(!clk->usecount) has
already dereferenced clk (and possibly crashed). You might need two
statements if its likely that clk could be NULL.
> - __clk_disable(clk->parent);
> - __clk_disable(clk->secondary);
> -
> - WARN_ON(!clk->usecount);
> - if (!(--clk->usecount)&& clk->disable)
> - clk->disable(clk);
> + if (!(--clk->usecount)) {
> + if (clk->disable)
> + clk->disable(clk);
> + __clk_disable(clk->parent);
> + __clk_disable(clk->secondary);
> + }
> }
>
> static int __clk_enable(struct clk *clk)
> @@ -66,12 +67,13 @@ static int __clk_enable(struct clk *clk)
> if (clk == NULL || IS_ERR(clk))
> return -EINVAL;
>
> - __clk_enable(clk->parent);
> - __clk_enable(clk->secondary);
> -
> - if (clk->usecount++ == 0&& clk->enable)
> - clk->enable(clk);
> + if (clk->usecount++ == 0) {
> + __clk_enable(clk->parent);
> + __clk_enable(clk->secondary);
>
> + if (clk->enable)
> + clk->enable(clk);
> + }
> return 0;
> }
>
> @@ -160,17 +162,25 @@ EXPORT_SYMBOL(clk_set_rate);
> int clk_set_parent(struct clk *clk, struct clk *parent)
> {
> int ret = -EINVAL;
> + struct clk *prev_parent = clk->parent;
>
> if (clk == NULL || IS_ERR(clk) || parent == NULL ||
> IS_ERR(parent) || clk->set_parent == NULL)
> return ret;
>
> + if (clk->usecount != 0)
> + clk_enable(parent);
> +
> mutex_lock(&clocks_mutex);
> ret = clk->set_parent(clk, parent);
> if (ret == 0)
> clk->parent = parent;
> +
> mutex_unlock(&clocks_mutex);
>
> + if (clk->usecount != 0)
> + clk_disable(prev_parent);
> +
> return ret;
> }
> EXPORT_SYMBOL(clk_set_parent);
--
Tim Gardner tim.gardner at canonical.com
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 1/1] arm: mxc: utilise usecount field in clock operations
2010-04-22 23:00 ` Tim Gardner
@ 2010-05-28 8:29 ` Amit Kucheria
0 siblings, 0 replies; 3+ messages in thread
From: Amit Kucheria @ 2010-05-28 8:29 UTC (permalink / raw)
To: linux-arm-kernel
On 10 Apr 22, Tim Gardner wrote:
> On 04/22/2010 02:30 PM, Amit Kucheria wrote:
> >From: Amit Kucheria<amit.kucheria@canonical.com>
> >
> >This patch fixes the clock refcounting when reparenting is used.
> >
> >Sascha just pointed out a good explanation of refcounting here:
> >http://www.spinics.net/lists/arm-kernel/msg85879.html
> >
> >Signed-off-by: Amit Kucheria<amit.kucheria@canonical.com>
> >---
> > arch/arm/plat-mxc/clock.c | 34 ++++++++++++++++++++++------------
> > 1 files changed, 22 insertions(+), 12 deletions(-)
> >
> >diff --git a/arch/arm/plat-mxc/clock.c b/arch/arm/plat-mxc/clock.c
> >index 323ff8c..14781cc 100644
> >--- a/arch/arm/plat-mxc/clock.c
> >+++ b/arch/arm/plat-mxc/clock.c
> >@@ -50,15 +50,16 @@ static DEFINE_MUTEX(clocks_mutex);
> >
> > static void __clk_disable(struct clk *clk)
> > {
> >- if (clk == NULL || IS_ERR(clk))
> >+ WARN_ON(!clk->usecount);
> >+ if (clk == NULL || IS_ERR(clk) || !clk->usecount)
> > return;
> >
>
> The clk==NULL check seem superfluous if WARN_ON(!clk->usecount) has
> already dereferenced clk (and possibly crashed). You might need two
> statements if its likely that clk could be NULL.
>
Tim, You're right.
Sascha, updated patch to fix that issue and correspond more closely to
Russell's explanation follows.
Cheers,
Amit
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-05-28 8:29 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-22 20:30 [PATCH 1/1] arm: mxc: utilise usecount field in clock operations Amit Kucheria
2010-04-22 23:00 ` Tim Gardner
2010-05-28 8:29 ` Amit Kucheria
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).