ARM: davinci: da8xx: Fix sleeping function called from invalid context
Subsystems (3)
PATCH v3 1/1 ARM: davinci: da8xx: Fix sleeping function called from invalid context
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().
--- arch/arm/mach-davinci/usb-da8xx.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-)
arch/arm/mach-davinci/usb-da8xx.c +12 -11
@@ -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,16 @@ 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" ); + ret =PTR_ERR_OR_ZERO (usb20_clk); +if (ret) +return ret; + 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);
Signature · 1 line
2.7.3
PATCH v3 1/1 ARM: davinci: da8xx: Fix sleeping function called from invalid context
Quoted 1 line · Alexandre Bailon
Everytime the usb20 phy is enabled, there is a
Every time is two words
Quoted 19 lines
"sleeping function called from invalid context" BUG.
clk_enable()fromarch/arm/mach-davinci/clock.cusesspin_lock_irqsave()before to invoke the callbackusb20_phy_clk_enable().usb20_phy_clk_enable()usesclk_get()andclk_enable_prepapre()which may sleep.
Moveclk_get()toda8xx_register_usb20_phy_clk()and
replaceclk_prepare_enable()byclk_enable().Signed-off-by Alexandre Bailon <[email protected]>--- arch/arm/mach-davinci/usb-da8xx.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-)arch/arm/mach-davinci/usb-da8xx.c +0
-0
arch/arm/mach-davinci/usb-da8xx.c int __init da8xx_register_usb_refclkin(int rate) · line 159
Quoted 4 lines
arch/arm/mach-davinci/usb-da8xx.c +1
-0@@ -156,23 +156,18 @@ int __init da8xx_register_usb_refclkin(int rate)return 0 ; } +static struct clk *usb20_clk;
Not a serious issue, but I would rather have the global variable declared at the beginning of the file to make it more obvious there is a global variable.
Quoted 33 lines
arch/arm/mach-davinci/usb-da8xx.c +3
-10+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)
arch/arm/mach-davinci/usb-da8xx.c int __init da8xx_register_usb20_phy_clk(bool use_usb_refclkin) · line 282
Quoted 2 lines
arch/arm/mach-davinci/usb-da8xx.c +0
-0@@ -287,9 +281,16 @@ int __init da8xx_register_usb20_phy_clk(bool use_usb_refclkin)struct clk *parent;int ret =0 ;
No longer need to initialize ret here.
arch/arm/mach-davinci/usb-da8xx.c int __init da8xx_register_usb20_phy_clk(bool use_usb_refclkin) · line 290
Quoted 9 lines
arch/arm/mach-davinci/usb-da8xx.c +6
-1+ usb20_clk =clk_get (&da8xx_usb20_dev.dev,"usb20" ); + ret =PTR_ERR_OR_ZERO (usb20_clk); +if (ret) +return ret; + parent =clk_get (NULL , use_usb_refclkin ?"usb_refclkin" :"pll0_aux" ); -if (IS_ERR (parent)) +if (IS_ERR (parent)) {
why not use ret = PTR_ERR_OR_ZERO(parent) pattern here too?
arch/arm/mach-davinci/usb-da8xx.c int __init da8xx_register_usb20_phy_clk(bool use_usb_refclkin) · line 291
Quoted 1 line
arch/arm/mach-davinci/usb-da8xx.c +1
-0+clk_put (usb20_clk);
The global usb20_clk is no longer valid after this. Should we set it to NULL here?
Quoted 6 lines
arch/arm/mach-davinci/usb-da8xx.c +1
-0return PTR_ERR (parent); + } usb20_phy_clk.parent = parent; ret =clk_register (&usb20_phy_clk);
PATCH v3 1/1 ARM: davinci: da8xx: Fix sleeping function called from invalid context
Quoted 5 lines · David Lechner
Quoted 2 lines
+
clk_put(usb20_clk);The global
usb20_clkis no longer valid after this. Should we set it to NULL here?
No need of this. Also, NULL is valid clock handle.
Thanks,
Sekhar