Re: Locking in the clk API, part 2: clk_prepare/clk_unprepare
From: Jassi Brar
Date: Fri Feb 04 2011 - 06:04:16 EST
On Fri, Feb 4, 2011 at 7:48 PM, Russell King - ARM Linux
<linux@xxxxxxxxxxxxxxxx> wrote:
> int clk_enable(struct clk *clk)
> {
> Â Â Â Âunsigned long flags;
> Â Â Â Âint ret = 0;
>
> Â Â Â Âif (clk) {
> Â Â Â Â Â Â Â Âif (WARN_ON(!clk->prepare_count))
> Â Â Â Â Â Â Â Â Â Â Â Âreturn -EINVAL;
>
> Â Â Â Â Â Â Â Âspin_lock_irqsave(&clk->lock, flags);
> Â Â Â Â Â Â Â Âif (clk->enable_count++ == 0)
> Â Â Â Â Â Â Â Â Â Â Â Âret = clk->ops->enable(clk);
> Â Â Â Â Â Â Â Âspin_unlock_irqrestore(&clk->lock, flags);
> Â Â Â Â}
> Â Â Â Âreturn ret;
> }
>
> is entirely sufficient to catch the case of a single-use clock not being
> prepared before clk_enable() is called.
>
> We're after detecting drivers missing calls to clk_prepare(), we're not
> after detecting concurrent calls to clk_prepare()/clk_unprepare().
I hope you mean 'making sure the clock is prepared before it's enabled
' rather than
'catching a driver that doesn't do clk_prepare before clk_enable'.
Because, the above implementation still doesn't catch a driver that
doesn't call clk_prepare
but simply uses a clock that happens to have been already prepare'd by
some other
driver or the platform.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/