diff options
author | Sylwester Nawrocki <s.nawrocki@samsung.com> | 2013-08-23 11:03:44 -0400 |
---|---|---|
committer | Sylwester Nawrocki <s.nawrocki@samsung.com> | 2013-12-04 11:19:36 -0500 |
commit | 3a3d2b0551d79ef476ef57424beeb8f68789fbcd (patch) | |
tree | 8dd517d6650876376d1d4e18b605b56fc59ace4b /drivers/clk/clkdev.c | |
parent | d6782c263661abd6c7e8a375141d69fdc457f9e1 (diff) |
clkdev: Fix race condition in clock lookup from device tree
There is currently a race condition in the device tree part of clk_get()
function, since the pointer returned from of_clk_get_by_name() may become
invalid before __clk_get() call. E.g. due to the clock provider driver
remove() callback being called in between of_clk_get_by_name() and
__clk_get().
Fix this by doing both the look up and __clk_get() operations with the
clock providers list mutex held. This ensures that the clock pointer
returned from __of_clk_get_from_provider() call and passed to __clk_get()
is valid, as long as the clock supplier module first removes its clock
provider instance and then does clk_unregister() on the corresponding
clocks.
Signed-off-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Reviewed-by: Mike Turquette <mturquette@linaro.org>
Acked-by: Russell King <rmk+kernel@arm.linux.org.uk>
Diffstat (limited to 'drivers/clk/clkdev.c')
-rw-r--r-- | drivers/clk/clkdev.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/drivers/clk/clkdev.c b/drivers/clk/clkdev.c index 442a31363873..48f67218247c 100644 --- a/drivers/clk/clkdev.c +++ b/drivers/clk/clkdev.c | |||
@@ -21,6 +21,8 @@ | |||
21 | #include <linux/clkdev.h> | 21 | #include <linux/clkdev.h> |
22 | #include <linux/of.h> | 22 | #include <linux/of.h> |
23 | 23 | ||
24 | #include "clk.h" | ||
25 | |||
24 | static LIST_HEAD(clocks); | 26 | static LIST_HEAD(clocks); |
25 | static DEFINE_MUTEX(clocks_mutex); | 27 | static DEFINE_MUTEX(clocks_mutex); |
26 | 28 | ||
@@ -39,7 +41,13 @@ struct clk *of_clk_get(struct device_node *np, int index) | |||
39 | if (rc) | 41 | if (rc) |
40 | return ERR_PTR(rc); | 42 | return ERR_PTR(rc); |
41 | 43 | ||
42 | clk = of_clk_get_from_provider(&clkspec); | 44 | of_clk_lock(); |
45 | clk = __of_clk_get_from_provider(&clkspec); | ||
46 | |||
47 | if (!IS_ERR(clk) && !__clk_get(clk)) | ||
48 | clk = ERR_PTR(-ENOENT); | ||
49 | |||
50 | of_clk_unlock(); | ||
43 | of_node_put(clkspec.np); | 51 | of_node_put(clkspec.np); |
44 | return clk; | 52 | return clk; |
45 | } | 53 | } |
@@ -157,7 +165,7 @@ struct clk *clk_get(struct device *dev, const char *con_id) | |||
157 | 165 | ||
158 | if (dev) { | 166 | if (dev) { |
159 | clk = of_clk_get_by_name(dev->of_node, con_id); | 167 | clk = of_clk_get_by_name(dev->of_node, con_id); |
160 | if (!IS_ERR(clk) && __clk_get(clk)) | 168 | if (!IS_ERR(clk)) |
161 | return clk; | 169 | return clk; |
162 | } | 170 | } |
163 | 171 | ||