linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] clk: gpio: Get parent clk names already in of_gpio_clk_setup()
       [not found] <201511170911.tAH9B0CF031498@arroyo.ext.ti.com>
@ 2015-11-17  9:56 ` Jyri Sarha
  2015-11-18 22:19   ` Stephen Boyd
  0 siblings, 1 reply; 3+ messages in thread
From: Jyri Sarha @ 2015-11-17  9:56 UTC (permalink / raw)
  To: linux-kernel, linux-omap
  Cc: Mike Turquette, sboyd, tomi.valkeinen, Jyri Sarha, Sergej Sawazki

Get parent clk names already in of_gpio_clk_setup() and store the
names in struct clk_gpio_delayed_register_data. of_clk_get_parent_name()
can not be called in struct of_clk_provider's get() callback since it
may make a recursive call to of_clk_get_from_provider() and this in turn
tries to recursively lock of_clk_mutex.

Signed-off-by: Jyri Sarha <jsarha@ti.com>
Cc: Sergej Sawazki <ce3a@gmx.de>
---
Something has changed in Linux mainline so that getting the clk
parent names in struct of_clk_provider's get() callback does not work
anymore. This patch should fix the problem.

 drivers/clk/clk-gpio.c | 33 +++++++++++++++++----------------
 1 file changed, 17 insertions(+), 16 deletions(-)

diff --git a/drivers/clk/clk-gpio.c b/drivers/clk/clk-gpio.c
index 10819e2..335322d 100644
--- a/drivers/clk/clk-gpio.c
+++ b/drivers/clk/clk-gpio.c
@@ -209,6 +209,8 @@ EXPORT_SYMBOL_GPL(clk_register_gpio_mux);
 
 struct clk_gpio_delayed_register_data {
 	const char *gpio_name;
+	int num_parents;
+	const char **parent_names;
 	struct device_node *node;
 	struct mutex lock;
 	struct clk *clk;
@@ -222,8 +224,6 @@ static struct clk *of_clk_gpio_delayed_register_get(
 {
 	struct clk_gpio_delayed_register_data *data = _data;
 	struct clk *clk;
-	const char **parent_names;
-	int i, num_parents;
 	int gpio;
 	enum of_gpio_flags of_flags;
 
@@ -248,26 +248,14 @@ static struct clk *of_clk_gpio_delayed_register_get(
 		return ERR_PTR(gpio);
 	}
 
-	num_parents = of_clk_get_parent_count(data->node);
-
-	parent_names = kcalloc(num_parents, sizeof(char *), GFP_KERNEL);
-	if (!parent_names) {
-		clk = ERR_PTR(-ENOMEM);
-		goto out;
-	}
-
-	for (i = 0; i < num_parents; i++)
-		parent_names[i] = of_clk_get_parent_name(data->node, i);
-
-	clk = data->clk_register_get(data->node->name, parent_names,
-			num_parents, gpio, of_flags & OF_GPIO_ACTIVE_LOW);
+	clk = data->clk_register_get(data->node->name, data->parent_names,
+			data->num_parents, gpio, of_flags & OF_GPIO_ACTIVE_LOW);
 	if (IS_ERR(clk))
 		goto out;
 
 	data->clk = clk;
 out:
 	mutex_unlock(&data->lock);
-	kfree(parent_names);
 
 	return clk;
 }
@@ -296,11 +284,24 @@ static void __init of_gpio_clk_setup(struct device_node *node,
 				unsigned gpio, bool active_low))
 {
 	struct clk_gpio_delayed_register_data *data;
+	const char **parent_names;
+	int i, num_parents;
 
 	data = kzalloc(sizeof(*data), GFP_KERNEL);
 	if (!data)
 		return;
 
+	num_parents = of_clk_get_parent_count(node);
+
+	parent_names = kcalloc(num_parents, sizeof(char *), GFP_KERNEL);
+	if (!parent_names)
+		return;
+
+	for (i = 0; i < num_parents; i++)
+		parent_names[i] = of_clk_get_parent_name(node, i);
+
+	data->num_parents = num_parents;
+	data->parent_names = parent_names;
 	data->node = node;
 	data->gpio_name = gpio_name;
 	data->clk_register_get = clk_register_get;
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] clk: gpio: Get parent clk names already in of_gpio_clk_setup()
  2015-11-17  9:56 ` [PATCH] clk: gpio: Get parent clk names already in of_gpio_clk_setup() Jyri Sarha
@ 2015-11-18 22:19   ` Stephen Boyd
  0 siblings, 0 replies; 3+ messages in thread
From: Stephen Boyd @ 2015-11-18 22:19 UTC (permalink / raw)
  To: Jyri Sarha
  Cc: linux-kernel, linux-omap, Mike Turquette, tomi.valkeinen, Sergej Sawazki

On 11/17, Jyri Sarha wrote:
> Get parent clk names already in of_gpio_clk_setup() and store the
> names in struct clk_gpio_delayed_register_data. of_clk_get_parent_name()
> can not be called in struct of_clk_provider's get() callback since it
> may make a recursive call to of_clk_get_from_provider() and this in turn
> tries to recursively lock of_clk_mutex.
> 
> Signed-off-by: Jyri Sarha <jsarha@ti.com>
> Cc: Sergej Sawazki <ce3a@gmx.de>
> ---
> Something has changed in Linux mainline so that getting the clk
> parent names in struct of_clk_provider's get() callback does not work
> anymore. This patch should fix the problem.

Something would be commit 0a4807c2f9a4 (clk: Make
of_clk_get_parent_name() robust with #clock-cells = 1, 2015-10-14)?

The patch looks good. Given that there's one user of this code in
mainline I'll push this as a fix for v4.4.

-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] clk: gpio: Get parent clk names already in of_gpio_clk_setup()
@ 2015-11-17  9:10 Jyri Sarha
  0 siblings, 0 replies; 3+ messages in thread
From: Jyri Sarha @ 2015-11-17  9:10 UTC (permalink / raw)
  To: linux-kernel, linux-omap, Mike Turquette
  Cc: tomi.valkeinen, Jyri Sarha, Sergej Sawazki

Get parent clk names already in of_gpio_clk_setup() and store the
names in struct clk_gpio_delayed_register_data. of_clk_get_parent_name()
can not be called in struct of_clk_provider's get() callback since it
may make a recursive call to of_clk_get_from_provider() and this in turn
tries to recursively lock of_clk_mutex.

Signed-off-by: Jyri Sarha <jsarha@ti.com>
Cc: Sergej Sawazki <ce3a@gmx.de>
---
Something has changed in Linux mainline so that getting the clk
parent names in struct of_clk_provider's get() callback does not work
anymore. This patch should fix the problem.

 drivers/clk/clk-gpio.c | 33 +++++++++++++++++----------------
 1 file changed, 17 insertions(+), 16 deletions(-)

diff --git a/drivers/clk/clk-gpio.c b/drivers/clk/clk-gpio.c
index 10819e2..335322d 100644
--- a/drivers/clk/clk-gpio.c
+++ b/drivers/clk/clk-gpio.c
@@ -209,6 +209,8 @@ EXPORT_SYMBOL_GPL(clk_register_gpio_mux);
 
 struct clk_gpio_delayed_register_data {
 	const char *gpio_name;
+	int num_parents;
+	const char **parent_names;
 	struct device_node *node;
 	struct mutex lock;
 	struct clk *clk;
@@ -222,8 +224,6 @@ static struct clk *of_clk_gpio_delayed_register_get(
 {
 	struct clk_gpio_delayed_register_data *data = _data;
 	struct clk *clk;
-	const char **parent_names;
-	int i, num_parents;
 	int gpio;
 	enum of_gpio_flags of_flags;
 
@@ -248,26 +248,14 @@ static struct clk *of_clk_gpio_delayed_register_get(
 		return ERR_PTR(gpio);
 	}
 
-	num_parents = of_clk_get_parent_count(data->node);
-
-	parent_names = kcalloc(num_parents, sizeof(char *), GFP_KERNEL);
-	if (!parent_names) {
-		clk = ERR_PTR(-ENOMEM);
-		goto out;
-	}
-
-	for (i = 0; i < num_parents; i++)
-		parent_names[i] = of_clk_get_parent_name(data->node, i);
-
-	clk = data->clk_register_get(data->node->name, parent_names,
-			num_parents, gpio, of_flags & OF_GPIO_ACTIVE_LOW);
+	clk = data->clk_register_get(data->node->name, data->parent_names,
+			data->num_parents, gpio, of_flags & OF_GPIO_ACTIVE_LOW);
 	if (IS_ERR(clk))
 		goto out;
 
 	data->clk = clk;
 out:
 	mutex_unlock(&data->lock);
-	kfree(parent_names);
 
 	return clk;
 }
@@ -296,11 +284,24 @@ static void __init of_gpio_clk_setup(struct device_node *node,
 				unsigned gpio, bool active_low))
 {
 	struct clk_gpio_delayed_register_data *data;
+	const char **parent_names;
+	int i, num_parents;
 
 	data = kzalloc(sizeof(*data), GFP_KERNEL);
 	if (!data)
 		return;
 
+	num_parents = of_clk_get_parent_count(node);
+
+	parent_names = kcalloc(num_parents, sizeof(char *), GFP_KERNEL);
+	if (!parent_names)
+		return;
+
+	for (i = 0; i < num_parents; i++)
+		parent_names[i] = of_clk_get_parent_name(node, i);
+
+	data->num_parents = num_parents;
+	data->parent_names = parent_names;
 	data->node = node;
 	data->gpio_name = gpio_name;
 	data->clk_register_get = clk_register_get;
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-11-18 22:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <201511170911.tAH9B0CF031498@arroyo.ext.ti.com>
2015-11-17  9:56 ` [PATCH] clk: gpio: Get parent clk names already in of_gpio_clk_setup() Jyri Sarha
2015-11-18 22:19   ` Stephen Boyd
2015-11-17  9:10 Jyri Sarha

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).