From: Masahiro Yamada <yamada.masahiro@socionext.com>
To: linux-clk@vger.kernel.org
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>,
Stephen Boyd <sboyd@codeaurora.org>,
Michael Turquette <mturquette@baylibre.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH 2/5] clk: avoid adding clock provider multiple times for one node
Date: Tue, 19 Jul 2016 18:21:35 +0900 [thread overview]
Message-ID: <1468920098-8553-3-git-send-email-yamada.masahiro@socionext.com> (raw)
In-Reply-To: <1468920098-8553-1-git-send-email-yamada.masahiro@socionext.com>
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
next prev parent reply other threads:[~2016-07-19 9:20 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-19 9:21 [PATCH 0/5] clk: forbit multiple adding of clock providers and fix false positive EPROBE_DEFER Masahiro Yamada
2016-07-19 9:21 ` [PATCH 1/5] clk: add a helper function __of_clk_find_provider() Masahiro Yamada
2016-07-19 9:21 ` Masahiro Yamada [this message]
2016-07-19 9:21 ` [PATCH 3/5] clk: refactor of_clk_del_provider() Masahiro Yamada
2016-07-19 9:21 ` [PATCH 4/5] clk: fix false positive EPROBE_DEFER of __of_clk_get_hw_from_provider() Masahiro Yamada
2016-07-19 9:21 ` [PATCH 5/5] clk: return -EINVAL if clock provider has no .get callback Masahiro Yamada
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1468920098-8553-3-git-send-email-yamada.masahiro@socionext.com \
--to=yamada.masahiro@socionext.com \
--cc=linux-clk@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mturquette@baylibre.com \
--cc=sboyd@codeaurora.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.