ARM: OMAP: clock: fix race in disable all clocks
authorNishanth Menon <nm@ti.com>
Thu, 15 Mar 2012 18:24:31 +0000 (13:24 -0500)
committerGrazvydas Ignotas <notasas@gmail.com>
Fri, 27 Apr 2012 16:43:31 +0000 (19:43 +0300)
commit4d1f04eccd94d66bb3a6aed8eb4c82844f7b176b
treeef06ba138e7ab07acfcdd1dc5e7c8a8199cdf9ff
parenta787f9dc598dd8d74b5be6a41bef9ae8e55f9263
ARM: OMAP: clock: fix race in disable all clocks

clk_disable_unused is invoked when CONFIG_OMAP_RESET_CLOCKS=y.
Since clk_disable_unused is called as lateinitcall, there can
be more than a few workqueues executing off secondary CPU(s).
The current code does the following:
a) checks if clk is unused
b) holds lock
c) disables clk
d) unlocks

Between (a) and (b) being executed on CPU0, It is possible to
have a driver executing on CPU1 which could do a get_sync->clk_get
(and increase the use_count) of the clock which was just about
to be disabled by clk_disable_unused.

We ensure instead that the entire list traversal is protected by
the lock allowing for parent child clock traversal which could be
potentially be done by runtime operations to be safe as well.

Reported-by: Todd Poynor <toddpoynor@google.com>
Signed-off-by: Nishanth Menon <nm@ti.com>
Signed-off-by: Paul Walmsley <paul@pwsan.com>
arch/arm/plat-omap/clock.c