All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] [RFC] pwm: sun4i: Move pwm_calculate out of spin_lock
@ 2020-01-09 23:31 Clément Péron
  2020-01-10  7:13   ` Uwe Kleine-König
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Clément Péron @ 2020-01-09 23:31 UTC (permalink / raw)
  To: Thierry Reding, Uwe Kleine-König
  Cc: linux-pwm, Clément Péron, Alex Mobigo, linux-arm-kernel

pwm_calculate calls clk_get_rate while holding a spin_lock.

This create an issue as clk_get_rate() may sleep.

Move pwm_calculate out of this spin_lock.

Fixes: c32c5c50d4fe ("pwm: sun4i: Switch to atomic PWM")
Reported-by: Alex Mobigo <alex.mobigo@gmail.com>
Suggested-by: Vasily Khoruzhick <anarsoul@gmail.com>
Signed-off-by: Clément Péron <peron.clem@gmail.com>
---

Hi,

this issue has been reported on linux-sunxi Google groups.

I don't have a board with PWM to confirm it.

Please wait a tested-by.

Thanks,
Clément

 drivers/pwm/pwm-sun4i.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/pwm/pwm-sun4i.c b/drivers/pwm/pwm-sun4i.c
index 1afd41ebd3fd..6b230029dc49 100644
--- a/drivers/pwm/pwm-sun4i.c
+++ b/drivers/pwm/pwm-sun4i.c
@@ -248,19 +248,18 @@ static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
 		}
 	}
 
-	spin_lock(&sun4i_pwm->ctrl_lock);
-	ctrl = sun4i_pwm_readl(sun4i_pwm, PWM_CTRL_REG);
-
 	ret = sun4i_pwm_calculate(sun4i_pwm, state, &duty, &period, &prescaler,
 				  &bypass);
 	if (ret) {
 		dev_err(chip->dev, "period exceeds the maximum value\n");
-		spin_unlock(&sun4i_pwm->ctrl_lock);
 		if (!cstate.enabled)
 			clk_disable_unprepare(sun4i_pwm->clk);
 		return ret;
 	}
 
+	spin_lock(&sun4i_pwm->ctrl_lock);
+	ctrl = sun4i_pwm_readl(sun4i_pwm, PWM_CTRL_REG);
+
 	if (sun4i_pwm->data->has_direct_mod_clk_output) {
 		if (bypass) {
 			ctrl |= BIT_CH(PWM_BYPASS, pwm->hwpwm);
-- 
2.20.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] [RFC] pwm: sun4i: Move pwm_calculate out of spin_lock
  2020-01-09 23:31 [PATCH] [RFC] pwm: sun4i: Move pwm_calculate out of spin_lock Clément Péron
@ 2020-01-10  7:13   ` Uwe Kleine-König
  2020-01-13  0:37 ` Alexander
  2020-01-13  0:39   ` Alexander
  2 siblings, 0 replies; 8+ messages in thread
From: Uwe Kleine-König @ 2020-01-10  7:13 UTC (permalink / raw)
  To: Clément Péron
  Cc: Thierry Reding, linux-pwm, linux-arm-kernel, Alex Mobigo,
	Vasily Khoruzhick, Michael Turquette, Stephen Boyd, linux-clk

Hello Clément,

On Fri, Jan 10, 2020 at 12:31:06AM +0100, Clément Péron wrote:
> pwm_calculate calls clk_get_rate while holding a spin_lock.
> 
> This create an issue as clk_get_rate() may sleep.

Slightly orthogonal to this issue, it might be a good idea to add a
might_sleep() to clk_get_rate(). (Added clk maintainers to Cc: for this
suggestion.)

> Move pwm_calculate out of this spin_lock.
> 
> Fixes: c32c5c50d4fe ("pwm: sun4i: Switch to atomic PWM")
> Reported-by: Alex Mobigo <alex.mobigo@gmail.com>
> Suggested-by: Vasily Khoruzhick <anarsoul@gmail.com>
> Signed-off-by: Clément Péron <peron.clem@gmail.com>
> ---
> 
> Hi,
> 
> this issue has been reported on linux-sunxi Google groups.
> 
> I don't have a board with PWM to confirm it.
> 
> Please wait a tested-by.
> 
> Thanks,
> Clément
> 
>  drivers/pwm/pwm-sun4i.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/pwm/pwm-sun4i.c b/drivers/pwm/pwm-sun4i.c
> index 1afd41ebd3fd..6b230029dc49 100644
> --- a/drivers/pwm/pwm-sun4i.c
> +++ b/drivers/pwm/pwm-sun4i.c
> @@ -248,19 +248,18 @@ static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
>  		}
>  	}
>  
> -	spin_lock(&sun4i_pwm->ctrl_lock);
> -	ctrl = sun4i_pwm_readl(sun4i_pwm, PWM_CTRL_REG);
> -
>  	ret = sun4i_pwm_calculate(sun4i_pwm, state, &duty, &period, &prescaler,
>  				  &bypass);
>  	if (ret) {
>  		dev_err(chip->dev, "period exceeds the maximum value\n");
> -		spin_unlock(&sun4i_pwm->ctrl_lock);
>  		if (!cstate.enabled)
>  			clk_disable_unprepare(sun4i_pwm->clk);
>  		return ret;
>  	}
>  
> +	spin_lock(&sun4i_pwm->ctrl_lock);
> +	ctrl = sun4i_pwm_readl(sun4i_pwm, PWM_CTRL_REG);
> +
>  	if (sun4i_pwm->data->has_direct_mod_clk_output) {
>  		if (bypass) {
>  			ctrl |= BIT_CH(PWM_BYPASS, pwm->hwpwm);

As sun4i_pwm_calculate does nothing that depends on (or modifies)
hardware state (apart from clk_get_rate(sun4i_pwm->clk) which can be
assumed to be constant) the change looks good.

Reviewed-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

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

* Re: [PATCH] [RFC] pwm: sun4i: Move pwm_calculate out of spin_lock
@ 2020-01-10  7:13   ` Uwe Kleine-König
  0 siblings, 0 replies; 8+ messages in thread
From: Uwe Kleine-König @ 2020-01-10  7:13 UTC (permalink / raw)
  To: Clément Péron
  Cc: linux-pwm, Stephen Boyd, Michael Turquette, linux-clk,
	Thierry Reding, Alex Mobigo, linux-arm-kernel

Hello Clément,

On Fri, Jan 10, 2020 at 12:31:06AM +0100, Clément Péron wrote:
> pwm_calculate calls clk_get_rate while holding a spin_lock.
> 
> This create an issue as clk_get_rate() may sleep.

Slightly orthogonal to this issue, it might be a good idea to add a
might_sleep() to clk_get_rate(). (Added clk maintainers to Cc: for this
suggestion.)

> Move pwm_calculate out of this spin_lock.
> 
> Fixes: c32c5c50d4fe ("pwm: sun4i: Switch to atomic PWM")
> Reported-by: Alex Mobigo <alex.mobigo@gmail.com>
> Suggested-by: Vasily Khoruzhick <anarsoul@gmail.com>
> Signed-off-by: Clément Péron <peron.clem@gmail.com>
> ---
> 
> Hi,
> 
> this issue has been reported on linux-sunxi Google groups.
> 
> I don't have a board with PWM to confirm it.
> 
> Please wait a tested-by.
> 
> Thanks,
> Clément
> 
>  drivers/pwm/pwm-sun4i.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/pwm/pwm-sun4i.c b/drivers/pwm/pwm-sun4i.c
> index 1afd41ebd3fd..6b230029dc49 100644
> --- a/drivers/pwm/pwm-sun4i.c
> +++ b/drivers/pwm/pwm-sun4i.c
> @@ -248,19 +248,18 @@ static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
>  		}
>  	}
>  
> -	spin_lock(&sun4i_pwm->ctrl_lock);
> -	ctrl = sun4i_pwm_readl(sun4i_pwm, PWM_CTRL_REG);
> -
>  	ret = sun4i_pwm_calculate(sun4i_pwm, state, &duty, &period, &prescaler,
>  				  &bypass);
>  	if (ret) {
>  		dev_err(chip->dev, "period exceeds the maximum value\n");
> -		spin_unlock(&sun4i_pwm->ctrl_lock);
>  		if (!cstate.enabled)
>  			clk_disable_unprepare(sun4i_pwm->clk);
>  		return ret;
>  	}
>  
> +	spin_lock(&sun4i_pwm->ctrl_lock);
> +	ctrl = sun4i_pwm_readl(sun4i_pwm, PWM_CTRL_REG);
> +
>  	if (sun4i_pwm->data->has_direct_mod_clk_output) {
>  		if (bypass) {
>  			ctrl |= BIT_CH(PWM_BYPASS, pwm->hwpwm);

As sun4i_pwm_calculate does nothing that depends on (or modifies)
hardware state (apart from clk_get_rate(sun4i_pwm->clk) which can be
assumed to be constant) the change looks good.

Reviewed-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] [RFC] pwm: sun4i: Move pwm_calculate out of spin_lock
  2020-01-09 23:31 [PATCH] [RFC] pwm: sun4i: Move pwm_calculate out of spin_lock Clément Péron
  2020-01-10  7:13   ` Uwe Kleine-König
@ 2020-01-13  0:37 ` Alexander
  2020-01-13  0:39   ` Alexander
  2 siblings, 0 replies; 8+ messages in thread
From: Alexander @ 2020-01-13  0:37 UTC (permalink / raw)
  To: Clément Péron
  Cc: Thierry Reding, Uwe Kleine-König, linux-pwm,
	linux-arm-kernel, Vasily Khoruzhick

[-- Attachment #1: Type: text/plain, Size: 2082 bytes --]

On Thu, Jan 9, 2020 at 8:31 PM Clément Péron <peron.clem@gmail.com> wrote:
>
> pwm_calculate calls clk_get_rate while holding a spin_lock.
>
> This create an issue as clk_get_rate() may sleep.
>
> Move pwm_calculate out of this spin_lock.
>
> Fixes: c32c5c50d4fe ("pwm: sun4i: Switch to atomic PWM")
> Reported-by: Alex Mobigo <alex.mobigo@gmail.com>
> Suggested-by: Vasily Khoruzhick <anarsoul@gmail.com>
> Signed-off-by: Clément Péron <peron.clem@gmail.com>
> ---
>
> Hi,
>
> this issue has been reported on linux-sunxi Google groups.
>
> I don't have a board with PWM to confirm it.
>
> Please wait a tested-by.
>
> Thanks,
> Clément
>
>  drivers/pwm/pwm-sun4i.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/pwm/pwm-sun4i.c b/drivers/pwm/pwm-sun4i.c
> index 1afd41ebd3fd..6b230029dc49 100644
> --- a/drivers/pwm/pwm-sun4i.c
> +++ b/drivers/pwm/pwm-sun4i.c
> @@ -248,19 +248,18 @@ static int sun4i_pwm_apply(struct pwm_chip *chip,
struct pwm_device *pwm,
>                 }
>         }
>
> -       spin_lock(&sun4i_pwm->ctrl_lock);
> -       ctrl = sun4i_pwm_readl(sun4i_pwm, PWM_CTRL_REG);
> -
>         ret = sun4i_pwm_calculate(sun4i_pwm, state, &duty, &period,
&prescaler,
>                                   &bypass);
>         if (ret) {
>                 dev_err(chip->dev, "period exceeds the maximum value\n");
> -               spin_unlock(&sun4i_pwm->ctrl_lock);
>                 if (!cstate.enabled)
>                         clk_disable_unprepare(sun4i_pwm->clk);
>                 return ret;
>         }
>
> +       spin_lock(&sun4i_pwm->ctrl_lock);
> +       ctrl = sun4i_pwm_readl(sun4i_pwm, PWM_CTRL_REG);
> +
>         if (sun4i_pwm->data->has_direct_mod_clk_output) {
>                 if (bypass) {
>                         ctrl |= BIT_CH(PWM_BYPASS, pwm->hwpwm);
> --
> 2.20.1
"""""""""""""""""
Tested on my board Pine64+, problems occurs before the patch but not
after...

Tested-By: Alexander Finger <alex.mobigo@gmail.com>
"""""""""""""""

[-- Attachment #2: Type: text/html, Size: 2996 bytes --]

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

* Re: [PATCH] [RFC] pwm: sun4i: Move pwm_calculate out of spin_lock
  2020-01-09 23:31 [PATCH] [RFC] pwm: sun4i: Move pwm_calculate out of spin_lock Clément Péron
@ 2020-01-13  0:39   ` Alexander
  2020-01-13  0:37 ` Alexander
  2020-01-13  0:39   ` Alexander
  2 siblings, 0 replies; 8+ messages in thread
From: Alexander @ 2020-01-13  0:39 UTC (permalink / raw)
  To: Clément Péron
  Cc: Thierry Reding, Uwe Kleine-König, linux-pwm,
	linux-arm-kernel, Vasily Khoruzhick

On Thu, Jan 9, 2020 at 8:31 PM Clément Péron <peron.clem@gmail.com> wrote:
>
> pwm_calculate calls clk_get_rate while holding a spin_lock.
>
> This create an issue as clk_get_rate() may sleep.
>
> Move pwm_calculate out of this spin_lock.
>
> Fixes: c32c5c50d4fe ("pwm: sun4i: Switch to atomic PWM")
> Reported-by: Alex Mobigo <alex.mobigo@gmail.com>
> Suggested-by: Vasily Khoruzhick <anarsoul@gmail.com>
> Signed-off-by: Clément Péron <peron.clem@gmail.com>
> ---
>
> Hi,
>
> this issue has been reported on linux-sunxi Google groups.
>
> I don't have a board with PWM to confirm it.
>
> Please wait a tested-by.
>
> Thanks,
> Clément
>
>  drivers/pwm/pwm-sun4i.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/pwm/pwm-sun4i.c b/drivers/pwm/pwm-sun4i.c
> index 1afd41ebd3fd..6b230029dc49 100644
> --- a/drivers/pwm/pwm-sun4i.c
> +++ b/drivers/pwm/pwm-sun4i.c
> @@ -248,19 +248,18 @@ static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
>                 }
>         }
>
> -       spin_lock(&sun4i_pwm->ctrl_lock);
> -       ctrl = sun4i_pwm_readl(sun4i_pwm, PWM_CTRL_REG);
> -
>         ret = sun4i_pwm_calculate(sun4i_pwm, state, &duty, &period, &prescaler,
>                                   &bypass);
>         if (ret) {
>                 dev_err(chip->dev, "period exceeds the maximum value\n");
> -               spin_unlock(&sun4i_pwm->ctrl_lock);
>                 if (!cstate.enabled)
>                         clk_disable_unprepare(sun4i_pwm->clk);
>                 return ret;
>         }
>
> +       spin_lock(&sun4i_pwm->ctrl_lock);
> +       ctrl = sun4i_pwm_readl(sun4i_pwm, PWM_CTRL_REG);
> +
>         if (sun4i_pwm->data->has_direct_mod_clk_output) {
>                 if (bypass) {
>                         ctrl |= BIT_CH(PWM_BYPASS, pwm->hwpwm);
> --
> 2.20.1
>
"""""""""""""""""
Tested on my board Pine64+, problems occurs before the patch but not after...

Tested-By: Alexander Finger <alex.mobigo@gmail.com>
"""""""""""""""

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

* Re: [PATCH] [RFC] pwm: sun4i: Move pwm_calculate out of spin_lock
@ 2020-01-13  0:39   ` Alexander
  0 siblings, 0 replies; 8+ messages in thread
From: Alexander @ 2020-01-13  0:39 UTC (permalink / raw)
  To: Clément Péron
  Cc: linux-pwm, Thierry Reding, linux-arm-kernel, Uwe Kleine-König

On Thu, Jan 9, 2020 at 8:31 PM Clément Péron <peron.clem@gmail.com> wrote:
>
> pwm_calculate calls clk_get_rate while holding a spin_lock.
>
> This create an issue as clk_get_rate() may sleep.
>
> Move pwm_calculate out of this spin_lock.
>
> Fixes: c32c5c50d4fe ("pwm: sun4i: Switch to atomic PWM")
> Reported-by: Alex Mobigo <alex.mobigo@gmail.com>
> Suggested-by: Vasily Khoruzhick <anarsoul@gmail.com>
> Signed-off-by: Clément Péron <peron.clem@gmail.com>
> ---
>
> Hi,
>
> this issue has been reported on linux-sunxi Google groups.
>
> I don't have a board with PWM to confirm it.
>
> Please wait a tested-by.
>
> Thanks,
> Clément
>
>  drivers/pwm/pwm-sun4i.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/pwm/pwm-sun4i.c b/drivers/pwm/pwm-sun4i.c
> index 1afd41ebd3fd..6b230029dc49 100644
> --- a/drivers/pwm/pwm-sun4i.c
> +++ b/drivers/pwm/pwm-sun4i.c
> @@ -248,19 +248,18 @@ static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
>                 }
>         }
>
> -       spin_lock(&sun4i_pwm->ctrl_lock);
> -       ctrl = sun4i_pwm_readl(sun4i_pwm, PWM_CTRL_REG);
> -
>         ret = sun4i_pwm_calculate(sun4i_pwm, state, &duty, &period, &prescaler,
>                                   &bypass);
>         if (ret) {
>                 dev_err(chip->dev, "period exceeds the maximum value\n");
> -               spin_unlock(&sun4i_pwm->ctrl_lock);
>                 if (!cstate.enabled)
>                         clk_disable_unprepare(sun4i_pwm->clk);
>                 return ret;
>         }
>
> +       spin_lock(&sun4i_pwm->ctrl_lock);
> +       ctrl = sun4i_pwm_readl(sun4i_pwm, PWM_CTRL_REG);
> +
>         if (sun4i_pwm->data->has_direct_mod_clk_output) {
>                 if (bypass) {
>                         ctrl |= BIT_CH(PWM_BYPASS, pwm->hwpwm);
> --
> 2.20.1
>
"""""""""""""""""
Tested on my board Pine64+, problems occurs before the patch but not after...

Tested-By: Alexander Finger <alex.mobigo@gmail.com>
"""""""""""""""

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] [RFC] pwm: sun4i: Move pwm_calculate out of spin_lock
  2020-01-13  0:39   ` Alexander
@ 2020-01-13  9:18     ` Clément Péron
  -1 siblings, 0 replies; 8+ messages in thread
From: Clément Péron @ 2020-01-13  9:18 UTC (permalink / raw)
  To: Alexander
  Cc: Thierry Reding, Uwe Kleine-König, Linux PWM List,
	linux-arm-kernel, Vasily Khoruzhick

Hi,

On Mon, 13 Jan 2020 at 01:40, Alexander <alex.mobigo@gmail.com> wrote:
>
> On Thu, Jan 9, 2020 at 8:31 PM Clément Péron <peron.clem@gmail.com> wrote:
> >
> > pwm_calculate calls clk_get_rate while holding a spin_lock.
> >
> > This create an issue as clk_get_rate() may sleep.
> >
> > Move pwm_calculate out of this spin_lock.
> >
> > Fixes: c32c5c50d4fe ("pwm: sun4i: Switch to atomic PWM")
> > Reported-by: Alex Mobigo <alex.mobigo@gmail.com>
> > Suggested-by: Vasily Khoruzhick <anarsoul@gmail.com>
> > Signed-off-by: Clément Péron <peron.clem@gmail.com>
> > ---
> >
> > Hi,
> >
> > this issue has been reported on linux-sunxi Google groups.
> >
> > I don't have a board with PWM to confirm it.
> >
> > Please wait a tested-by.
> >
> > Thanks,
> > Clément
> >
> >  drivers/pwm/pwm-sun4i.c | 7 +++----
> >  1 file changed, 3 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/pwm/pwm-sun4i.c b/drivers/pwm/pwm-sun4i.c
> > index 1afd41ebd3fd..6b230029dc49 100644
> > --- a/drivers/pwm/pwm-sun4i.c
> > +++ b/drivers/pwm/pwm-sun4i.c
> > @@ -248,19 +248,18 @@ static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
> >                 }
> >         }
> >
> > -       spin_lock(&sun4i_pwm->ctrl_lock);
> > -       ctrl = sun4i_pwm_readl(sun4i_pwm, PWM_CTRL_REG);
> > -
> >         ret = sun4i_pwm_calculate(sun4i_pwm, state, &duty, &period, &prescaler,
> >                                   &bypass);
> >         if (ret) {
> >                 dev_err(chip->dev, "period exceeds the maximum value\n");
> > -               spin_unlock(&sun4i_pwm->ctrl_lock);
> >                 if (!cstate.enabled)
> >                         clk_disable_unprepare(sun4i_pwm->clk);
> >                 return ret;
> >         }
> >
> > +       spin_lock(&sun4i_pwm->ctrl_lock);
> > +       ctrl = sun4i_pwm_readl(sun4i_pwm, PWM_CTRL_REG);
> > +
> >         if (sun4i_pwm->data->has_direct_mod_clk_output) {
> >                 if (bypass) {
> >                         ctrl |= BIT_CH(PWM_BYPASS, pwm->hwpwm);
> > --
> > 2.20.1
> >
> """""""""""""""""
> Tested on my board Pine64+, problems occurs before the patch but not after...
>
> Tested-By: Alexander Finger <alex.mobigo@gmail.com>

Thanks, I will send a v2 with your proper name for the Reported-by tag

Regards,
Clement

> """""""""""""""

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

* Re: [PATCH] [RFC] pwm: sun4i: Move pwm_calculate out of spin_lock
@ 2020-01-13  9:18     ` Clément Péron
  0 siblings, 0 replies; 8+ messages in thread
From: Clément Péron @ 2020-01-13  9:18 UTC (permalink / raw)
  To: Alexander
  Cc: Linux PWM List, Thierry Reding, linux-arm-kernel, Uwe Kleine-König

Hi,

On Mon, 13 Jan 2020 at 01:40, Alexander <alex.mobigo@gmail.com> wrote:
>
> On Thu, Jan 9, 2020 at 8:31 PM Clément Péron <peron.clem@gmail.com> wrote:
> >
> > pwm_calculate calls clk_get_rate while holding a spin_lock.
> >
> > This create an issue as clk_get_rate() may sleep.
> >
> > Move pwm_calculate out of this spin_lock.
> >
> > Fixes: c32c5c50d4fe ("pwm: sun4i: Switch to atomic PWM")
> > Reported-by: Alex Mobigo <alex.mobigo@gmail.com>
> > Suggested-by: Vasily Khoruzhick <anarsoul@gmail.com>
> > Signed-off-by: Clément Péron <peron.clem@gmail.com>
> > ---
> >
> > Hi,
> >
> > this issue has been reported on linux-sunxi Google groups.
> >
> > I don't have a board with PWM to confirm it.
> >
> > Please wait a tested-by.
> >
> > Thanks,
> > Clément
> >
> >  drivers/pwm/pwm-sun4i.c | 7 +++----
> >  1 file changed, 3 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/pwm/pwm-sun4i.c b/drivers/pwm/pwm-sun4i.c
> > index 1afd41ebd3fd..6b230029dc49 100644
> > --- a/drivers/pwm/pwm-sun4i.c
> > +++ b/drivers/pwm/pwm-sun4i.c
> > @@ -248,19 +248,18 @@ static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
> >                 }
> >         }
> >
> > -       spin_lock(&sun4i_pwm->ctrl_lock);
> > -       ctrl = sun4i_pwm_readl(sun4i_pwm, PWM_CTRL_REG);
> > -
> >         ret = sun4i_pwm_calculate(sun4i_pwm, state, &duty, &period, &prescaler,
> >                                   &bypass);
> >         if (ret) {
> >                 dev_err(chip->dev, "period exceeds the maximum value\n");
> > -               spin_unlock(&sun4i_pwm->ctrl_lock);
> >                 if (!cstate.enabled)
> >                         clk_disable_unprepare(sun4i_pwm->clk);
> >                 return ret;
> >         }
> >
> > +       spin_lock(&sun4i_pwm->ctrl_lock);
> > +       ctrl = sun4i_pwm_readl(sun4i_pwm, PWM_CTRL_REG);
> > +
> >         if (sun4i_pwm->data->has_direct_mod_clk_output) {
> >                 if (bypass) {
> >                         ctrl |= BIT_CH(PWM_BYPASS, pwm->hwpwm);
> > --
> > 2.20.1
> >
> """""""""""""""""
> Tested on my board Pine64+, problems occurs before the patch but not after...
>
> Tested-By: Alexander Finger <alex.mobigo@gmail.com>

Thanks, I will send a v2 with your proper name for the Reported-by tag

Regards,
Clement

> """""""""""""""

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2020-01-13  9:19 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-09 23:31 [PATCH] [RFC] pwm: sun4i: Move pwm_calculate out of spin_lock Clément Péron
2020-01-10  7:13 ` Uwe Kleine-König
2020-01-10  7:13   ` Uwe Kleine-König
2020-01-13  0:37 ` Alexander
2020-01-13  0:39 ` Alexander
2020-01-13  0:39   ` Alexander
2020-01-13  9:18   ` Clément Péron
2020-01-13  9:18     ` Clément Péron

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.