Skip to content

Commit d6782c2

Browse files
author
Sylwester Nawrocki
committed
clk: Provide not locked variant of of_clk_get_from_provider()
Add helper functions for the of_clk_providers list locking and an unlocked variant of of_clk_get_from_provider(). These functions are intended to be used in the clkdev to avoid race condition in the device tree based clock look up in clk_get(). Signed-off-by: Sylwester Nawrocki <s.nawrocki@samsung.com> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com> Acked-by: Russell King <rmk+kernel@arm.linux.org.uk>
1 parent 4eadfc3 commit d6782c2

File tree

2 files changed

+46
-8
lines changed

2 files changed

+46
-8
lines changed

drivers/clk/clk.c

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include <linux/init.h>
2222
#include <linux/sched.h>
2323

24+
#include "clk.h"
25+
2426
static DEFINE_SPINLOCK(enable_lock);
2527
static DEFINE_MUTEX(prepare_lock);
2628

@@ -2111,7 +2113,18 @@ static const struct of_device_id __clk_of_table_sentinel
21112113
__used __section(__clk_of_table_end);
21122114

21132115
static LIST_HEAD(of_clk_providers);
2114-
static DEFINE_MUTEX(of_clk_lock);
2116+
static DEFINE_MUTEX(of_clk_mutex);
2117+
2118+
/* of_clk_provider list locking helpers */
2119+
void of_clk_lock(void)
2120+
{
2121+
mutex_lock(&of_clk_mutex);
2122+
}
2123+
2124+
void of_clk_unlock(void)
2125+
{
2126+
mutex_unlock(&of_clk_mutex);
2127+
}
21152128

21162129
struct clk *of_clk_src_simple_get(struct of_phandle_args *clkspec,
21172130
void *data)
@@ -2155,9 +2168,9 @@ int of_clk_add_provider(struct device_node *np,
21552168
cp->data = data;
21562169
cp->get = clk_src_get;
21572170

2158-
mutex_lock(&of_clk_lock);
2171+
mutex_lock(&of_clk_mutex);
21592172
list_add(&cp->link, &of_clk_providers);
2160-
mutex_unlock(&of_clk_lock);
2173+
mutex_unlock(&of_clk_mutex);
21612174
pr_debug("Added clock from %s\n", np->full_name);
21622175

21632176
return 0;
@@ -2172,7 +2185,7 @@ void of_clk_del_provider(struct device_node *np)
21722185
{
21732186
struct of_clk_provider *cp;
21742187

2175-
mutex_lock(&of_clk_lock);
2188+
mutex_lock(&of_clk_mutex);
21762189
list_for_each_entry(cp, &of_clk_providers, link) {
21772190
if (cp->node == np) {
21782191
list_del(&cp->link);
@@ -2181,24 +2194,33 @@ void of_clk_del_provider(struct device_node *np)
21812194
break;
21822195
}
21832196
}
2184-
mutex_unlock(&of_clk_lock);
2197+
mutex_unlock(&of_clk_mutex);
21852198
}
21862199
EXPORT_SYMBOL_GPL(of_clk_del_provider);
21872200

2188-
struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec)
2201+
struct clk *__of_clk_get_from_provider(struct of_phandle_args *clkspec)
21892202
{
21902203
struct of_clk_provider *provider;
21912204
struct clk *clk = ERR_PTR(-ENOENT);
21922205

21932206
/* Check if we have such a provider in our array */
2194-
mutex_lock(&of_clk_lock);
21952207
list_for_each_entry(provider, &of_clk_providers, link) {
21962208
if (provider->node == clkspec->np)
21972209
clk = provider->get(clkspec, provider->data);
21982210
if (!IS_ERR(clk))
21992211
break;
22002212
}
2201-
mutex_unlock(&of_clk_lock);
2213+
2214+
return clk;
2215+
}
2216+
2217+
struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec)
2218+
{
2219+
struct clk *clk;
2220+
2221+
mutex_lock(&of_clk_mutex);
2222+
clk = __of_clk_get_from_provider(clkspec);
2223+
mutex_unlock(&of_clk_mutex);
22022224

22032225
return clk;
22042226
}

drivers/clk/clk.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* linux/drivers/clk/clk.h
3+
*
4+
* Copyright (C) 2013 Samsung Electronics Co., Ltd.
5+
* Sylwester Nawrocki <s.nawrocki@samsung.com>
6+
*
7+
* This program is free software; you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License version 2 as
9+
* published by the Free Software Foundation.
10+
*/
11+
12+
#if defined(CONFIG_OF) && defined(CONFIG_COMMON_CLK)
13+
struct clk *__of_clk_get_from_provider(struct of_phandle_args *clkspec);
14+
void of_clk_lock(void);
15+
void of_clk_unlock(void);
16+
#endif

0 commit comments

Comments
 (0)