clkdev: Hold clocks_mutex while iterating clocks list
authorStephen Boyd <sboyd@kernel.org>
Fri, 12 Apr 2019 18:31:42 +0000 (11:31 -0700)
committerStephen Boyd <sboyd@kernel.org>
Thu, 18 Apr 2019 20:33:13 +0000 (13:33 -0700)
commit5a7efdacb9dda1c35fb414d57b3e16d520e2c0db
tree84b3aaa6884fc4324e3bedff8c057b6bf74df0c9
parentf89b9e1be7da8bb0aac667a0206a00975cefe6d3
clkdev: Hold clocks_mutex while iterating clocks list

We recently introduced a change to support devm clk lookups. That change
introduced a code-path that used clk_find() without holding the
'clocks_mutex'. Unfortunately, clk_find() iterates over the 'clocks'
list and so we need to prevent the list from being modified at the same
time. Do this by holding the mutex and checking to make sure it's held
while iterating the list.

Note, we don't really care if the lookup is freed after we find it with
clk_find() because we're just doing a pointer comparison, but if we did
care we would need to keep holding the mutex while we dereference the
clk_lookup pointer.

Fixes: 3eee6c7d119c ("clkdev: add managed clkdev lookup registration")
Cc: Miquel Raynal <miquel.raynal@bootlin.com>
Cc: Jerome Brunet <jbrunet@baylibre.com>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Michael Turquette <mturquette@baylibre.com>
Cc: Jeffrey Hugo <jhugo@codeaurora.org>
Cc: Chen-Yu Tsai <wens@csie.org>
Cc: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
Acked-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
Tested-by: Jeffrey Hugo <jhugo@codeaurora.org>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
drivers/clk/clkdev.c