* [PATCH v2] ARM: davinci: da8xx: Fix sleeping function called from invalid context
@ 2016-11-29 16:48 Alexandre Bailon
2016-12-01 14:17 ` Sekhar Nori
0 siblings, 1 reply; 4+ messages in thread
From: Alexandre Bailon @ 2016-11-29 16:48 UTC (permalink / raw)
To: linux-arm-kernel
Everytime the usb20 phy is enabled, there is a
"sleeping function called from invalid context" BUG.
clk_enable() from arch/arm/mach-davinci/clock.c uses spin_lock_irqsave()
before to invoke the callback usb20_phy_clk_enable().
usb20_phy_clk_enable() uses clk_get() and clk_enable_prepapre()
which may sleep.
Move clk_get() to da8xx_register_usb20_phy_clk() and
replace clk_prepare_enable() by clk_enable().
Signed-off-by: Alexandre Bailon <abailon@baylibre.com>
---
arch/arm/mach-davinci/usb-da8xx.c | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/arch/arm/mach-davinci/usb-da8xx.c b/arch/arm/mach-davinci/usb-da8xx.c
index b010e5f..2baa0e1 100644
--- a/arch/arm/mach-davinci/usb-da8xx.c
+++ b/arch/arm/mach-davinci/usb-da8xx.c
@@ -156,23 +156,18 @@ int __init da8xx_register_usb_refclkin(int rate)
return 0;
}
+static struct clk *usb20_clk;
+
static void usb20_phy_clk_enable(struct clk *clk)
{
- struct clk *usb20_clk;
int err;
u32 val;
u32 timeout = 500000; /* 500 msec */
val = readl(DA8XX_SYSCFG0_VIRT(DA8XX_CFGCHIP2_REG));
- usb20_clk = clk_get(&da8xx_usb20_dev.dev, "usb20");
- if (IS_ERR(usb20_clk)) {
- pr_err("could not get usb20 clk: %ld\n", PTR_ERR(usb20_clk));
- return;
- }
-
/* The USB 2.O PLL requires that the USB 2.O PSC is enabled as well. */
- err = clk_prepare_enable(usb20_clk);
+ err = clk_enable(usb20_clk);
if (err) {
pr_err("failed to enable usb20 clk: %d\n", err);
clk_put(usb20_clk);
@@ -197,8 +192,7 @@ static void usb20_phy_clk_enable(struct clk *clk)
pr_err("Timeout waiting for USB 2.0 PHY clock good\n");
done:
- clk_disable_unprepare(usb20_clk);
- clk_put(usb20_clk);
+ clk_disable(usb20_clk);
}
static void usb20_phy_clk_disable(struct clk *clk)
@@ -287,9 +281,15 @@ int __init da8xx_register_usb20_phy_clk(bool use_usb_refclkin)
struct clk *parent;
int ret = 0;
+ usb20_clk = clk_get(&da8xx_usb20_dev.dev, "usb20");
+ if (IS_ERR(usb20_clk))
+ return PTR_ERR(parent);
+
parent = clk_get(NULL, use_usb_refclkin ? "usb_refclkin" : "pll0_aux");
- if (IS_ERR(parent))
+ if (IS_ERR(parent)) {
+ clk_put(usb20_clk);
return PTR_ERR(parent);
+ }
usb20_phy_clk.parent = parent;
ret = clk_register(&usb20_phy_clk);
--
2.7.3
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH v2] ARM: davinci: da8xx: Fix sleeping function called from invalid context
2016-11-29 16:48 [PATCH v2] ARM: davinci: da8xx: Fix sleeping function called from invalid context Alexandre Bailon
@ 2016-12-01 14:17 ` Sekhar Nori
2016-12-01 14:59 ` Arnd Bergmann
0 siblings, 1 reply; 4+ messages in thread
From: Sekhar Nori @ 2016-12-01 14:17 UTC (permalink / raw)
To: linux-arm-kernel
On Tuesday 29 November 2016 10:18 PM, Alexandre Bailon wrote:
> Everytime the usb20 phy is enabled, there is a
> "sleeping function called from invalid context" BUG.
>
> clk_enable() from arch/arm/mach-davinci/clock.c uses spin_lock_irqsave()
> before to invoke the callback usb20_phy_clk_enable().
"before invocation of the callback"? (doesn't read right otherwise)
> usb20_phy_clk_enable() uses clk_get() and clk_enable_prepapre()
clk_prepare_enable()
> which may sleep.
> Move clk_get() to da8xx_register_usb20_phy_clk() and
> replace clk_prepare_enable() by clk_enable().
>
> Signed-off-by: Alexandre Bailon <abailon@baylibre.com>
> @@ -287,9 +281,15 @@ int __init da8xx_register_usb20_phy_clk(bool use_usb_refclkin)
> struct clk *parent;
> int ret = 0;
>
> + usb20_clk = clk_get(&da8xx_usb20_dev.dev, "usb20");
> + if (IS_ERR(usb20_clk))
> + return PTR_ERR(parent);
Typo here. Should be PTR_ERR(usb20_clk)
Thanks,
Sekhar
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2] ARM: davinci: da8xx: Fix sleeping function called from invalid context
2016-12-01 14:17 ` Sekhar Nori
@ 2016-12-01 14:59 ` Arnd Bergmann
2016-12-01 17:04 ` Alexandre Bailon
0 siblings, 1 reply; 4+ messages in thread
From: Arnd Bergmann @ 2016-12-01 14:59 UTC (permalink / raw)
To: linux-arm-kernel
On Thursday, December 1, 2016 7:47:12 PM CET Sekhar Nori wrote:
>
> > @@ -287,9 +281,15 @@ int __init da8xx_register_usb20_phy_clk(bool use_usb_refclkin)
> > struct clk *parent;
> > int ret = 0;
> >
> > + usb20_clk = clk_get(&da8xx_usb20_dev.dev, "usb20");
> > + if (IS_ERR(usb20_clk))
> > + return PTR_ERR(parent);
>
> Typo here. Should be PTR_ERR(usb20_clk)
I found that doing
err = PTR_ERR_OR_ZERO(usb20_clk);
if (err)
return err;
is less error-prone and leads to better object code.
Arnd
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2] ARM: davinci: da8xx: Fix sleeping function called from invalid context
2016-12-01 14:59 ` Arnd Bergmann
@ 2016-12-01 17:04 ` Alexandre Bailon
0 siblings, 0 replies; 4+ messages in thread
From: Alexandre Bailon @ 2016-12-01 17:04 UTC (permalink / raw)
To: linux-arm-kernel
On 12/01/2016 03:59 PM, Arnd Bergmann wrote:
> On Thursday, December 1, 2016 7:47:12 PM CET Sekhar Nori wrote:
>>
>>> @@ -287,9 +281,15 @@ int __init da8xx_register_usb20_phy_clk(bool use_usb_refclkin)
>>> struct clk *parent;
>>> int ret = 0;
>>>
>>> + usb20_clk = clk_get(&da8xx_usb20_dev.dev, "usb20");
>>> + if (IS_ERR(usb20_clk))
>>> + return PTR_ERR(parent);
>>
>> Typo here. Should be PTR_ERR(usb20_clk)
>
> I found that doing
>
> err = PTR_ERR_OR_ZERO(usb20_clk);
> if (err)
> return err;
>
> is less error-prone and leads to better object code.
>
> Arnd
>
I didn't know that one.
I will use it.
Thanks,
Alexandre
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-12-01 17:04 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-29 16:48 [PATCH v2] ARM: davinci: da8xx: Fix sleeping function called from invalid context Alexandre Bailon
2016-12-01 14:17 ` Sekhar Nori
2016-12-01 14:59 ` Arnd Bergmann
2016-12-01 17:04 ` Alexandre Bailon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox