[PATCH] clk: Fix race conditions between clk_set_parent() and clk_enable()

Turquette, Mike mturquette at ti.com
Wed May 16 02:00:50 EDT 2012


On Fri, May 11, 2012 at 9:59 PM, Saravana Kannan <skannan at codeaurora.org> wrote:
> Since clocks with CLK_SET_PARENT_GATE flag only allow clk_set_parent() on
> unprepared clocks and calling clk_enable() on an unprepared clock would be
> violating the clock API usage model, allow set_parent() ops to be sleepable
> for clocks which have the CLK_SET_PARENT_GATE flag. Putting it another way,
> if a clock's parent can't be switched without sleeping, then by definition
> the parent can't be switched while it's prepared (CLK_SET_PARENT_GATE).
>
...
> diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
> index e5d5dc1..09b9112 100644
> --- a/drivers/clk/clk.c
> +++ b/drivers/clk/clk.c
> @@ -1059,7 +1059,7 @@ static int __clk_set_parent(struct clk *clk, struct clk *parent)
>  {
>        struct clk *old_parent;
>        unsigned long flags;
> -       int ret = -EINVAL;
> +       int ret;
>        u8 i;
>
>        old_parent = clk->parent;
> @@ -1083,7 +1083,13 @@ static int __clk_set_parent(struct clk *clk, struct clk *parent)
>        if (i == clk->num_parents) {
>                pr_debug("%s: clock %s is not a possible parent of clock %s\n",
>                                __func__, parent->name, clk->name);
> -               goto out;
> +               return -EINVAL;
> +       }
> +
> +       if (clk->flags & CLK_SET_PARENT_GATE) {
> +               ret = clk->ops->set_parent(clk->hw, i);
> +               clk->parent = parent;
> +               return ret;
>        }
>
>        /* migrate prepare and enable */

The above hunk is a good change since it fixes a bug where we
prepare/enable the parent clocks around the .set_parent callback, even
when CLK_SET_PARENT_GATE is set.  It should be a separate patch.

Thanks,
Mike



More information about the linux-arm-kernel mailing list