lkml.org 
[lkml]   [2016]   [Jul]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 2/5] clk: avoid adding clock provider multiple times for one node
Date
It is insane to add multiple OF clock providers against one device
node.

Let of_clk_add(_hw)_provider() fail with -EEXIST if the given node
is already associated with an OF clock provider.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---

drivers/clk/clk.c | 26 ++++++++++++++++++++++----
1 file changed, 22 insertions(+), 4 deletions(-)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index e8c79a7..7832343 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -3038,15 +3038,24 @@ int of_clk_add_provider(struct device_node *np,
struct of_clk_provider *cp;
int ret;

+ mutex_lock(&of_clk_mutex);
+
+ cp = __of_clk_find_provider(np);
+ if (cp) {
+ mutex_unlock(&of_clk_mutex);
+ return -EEXIST;
+ }
+
cp = kzalloc(sizeof(struct of_clk_provider), GFP_KERNEL);
- if (!cp)
+ if (!cp) {
+ mutex_unlock(&of_clk_mutex);
return -ENOMEM;
+ }

cp->node = of_node_get(np);
cp->data = data;
cp->get = clk_src_get;

- mutex_lock(&of_clk_mutex);
list_add(&cp->link, &of_clk_providers);
mutex_unlock(&of_clk_mutex);
pr_debug("Added clock from %s\n", np->full_name);
@@ -3073,15 +3082,24 @@ int of_clk_add_hw_provider(struct device_node *np,
struct of_clk_provider *cp;
int ret;

+ mutex_lock(&of_clk_mutex);
+
+ cp = __of_clk_find_provider(np);
+ if (cp) {
+ mutex_unlock(&of_clk_mutex);
+ return -EEXIST;
+ }
+
cp = kzalloc(sizeof(*cp), GFP_KERNEL);
- if (!cp)
+ if (!cp) {
+ mutex_unlock(&of_clk_mutex);
return -ENOMEM;
+ }

cp->node = of_node_get(np);
cp->data = data;
cp->get_hw = get;

- mutex_lock(&of_clk_mutex);
list_add(&cp->link, &of_clk_providers);
mutex_unlock(&of_clk_mutex);
pr_debug("Added clk_hw provider from %s\n", np->full_name);
--
1.9.1
\
 
 \ /
  Last update: 2016-07-19 12:01    [W:0.061 / U:0.696 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site