pwm: sun4i: Move pwm_calculate out of spin_lock
Subsystems (3)
RFC PATCH 1/1 pwm: sun4i: Move pwm_calculate out of spin_lock
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.
---
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(-)
drivers/pwm/pwm-sun4i.c +3 -4
@@ -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);
Signature · 7 lines
2.20.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Hello Clément,
Quoted 3 lines · Clément Péron
pwm_calculatecallsclk_get_ratewhile holding aspin_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.)
Quoted 39 lines
Move
pwm_calculateout of thisspin_lock.Fixes c32c5c50d4fe ("pwm: sun4i: Switch to atomic PWM")Reported-by Alex Mobigo <[email protected]>Suggested-by Vasily Khoruzhick <[email protected]>Signed-off-by Clément Péron <[email protected]>---
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émentdrivers/pwm/pwm-sun4i.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)drivers/pwm/pwm-sun4i.c +0
-4@@ -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)
drivers/pwm/pwm-sun4i.c static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, · line 265
Quoted 10 lines
drivers/pwm/pwm-sun4i.c +3
-0clk_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.
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | https://www.pengutronix.de/ |
drivers/pwm/pwm-sun4i.c static int sun4i_pwm_apply(struct pwm_chip *chip,
Quoted 32 lines · Clément Péron
pwm_calculatecallsclk_get_ratewhile holding aspin_lock.This create an issue as
clk_get_rate()may sleep.Move
pwm_calculateout of thisspin_lock.Fixes c32c5c50d4fe ("pwm: sun4i: Switch to atomic PWM")Reported-by Alex Mobigo <[email protected]>Suggested-by Vasily Khoruzhick <[email protected]>Signed-off-by Clément Péron <[email protected]>---
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émentdrivers/pwm/pwm-sun4i.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)drivers/pwm/pwm-sun4i.c +0
-0@@ -248,19 +248,18 @@ static int sun4i_pwm_apply(struct pwm_chip *chip,
struct pwm_device *pwm,
drivers/pwm/pwm-sun4i.c static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
Quoted 7 lines
drivers/pwm/pwm-sun4i.c +0
-3} } -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,
Quoted 16 lines
drivers/pwm/pwm-sun4i.c +3
-2&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); --
Quoted 1 line
2.20.1
"""""""""""""""""
Tested on my board Pine64+, problems occurs before the patch but not after...
"""""""""""""""
Quoted 55 lines · Clément Péron
pwm_calculatecallsclk_get_ratewhile holding aspin_lock.This create an issue as
clk_get_rate()may sleep.Move
pwm_calculateout of thisspin_lock.Fixes c32c5c50d4fe ("pwm: sun4i: Switch to atomic PWM")Reported-by Alex Mobigo <[email protected]>Suggested-by Vasily Khoruzhick <[email protected]>Signed-off-by Clément Péron <[email protected]>---
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émentdrivers/pwm/pwm-sun4i.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)drivers/pwm/pwm-sun4i.c +3
-5@@ -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); --
Quoted 2 lines
2.20.1
"""""""""""""""""
Tested on my board Pine64+, problems occurs before the patch but not after...
"""""""""""""""
Hi,
Quoted 62 lines · Alexander
Quoted 55 lines · Clément Péron
pwm_calculatecallsclk_get_ratewhile holding aspin_lock.This create an issue as
clk_get_rate()may sleep.Move
pwm_calculateout of thisspin_lock.Fixes c32c5c50d4fe ("pwm: sun4i: Switch to atomic PWM")Reported-by Alex Mobigo <[email protected]>Suggested-by Vasily Khoruzhick <[email protected]>Signed-off-by Clément Péron <[email protected]>---
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émentdrivers/pwm/pwm-sun4i.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)drivers/pwm/pwm-sun4i.c +3
-5@@ -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); --Quoted 2 lines
2.20.1
"""""""""""""""""
Tested on my board Pine64+, problems occurs before the patch but not after...
Quoted 1 line
Tested-by Alexander Finger <[email protected]>
Thanks, I will send a v2 with your proper name for the Reported-by tag
Regards,
Clement
Quoted 1 line
"""""""""""""""