From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: "Clément Péron" <peron.clem@gmail.com>
Cc: Thierry Reding <thierry.reding@gmail.com>,
linux-pwm@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
Alex Mobigo <alex.mobigo@gmail.com>,
Vasily Khoruzhick <anarsoul@gmail.com>,
Michael Turquette <mturquette@baylibre.com>,
Stephen Boyd <sboyd@kernel.org>,
linux-clk@vger.kernel.org
Subject: Re: [PATCH] [RFC] pwm: sun4i: Move pwm_calculate out of spin_lock
Date: Fri, 10 Jan 2020 08:13:06 +0100 [thread overview]
Message-ID: <20200110071306.uyqcyftb4bt7b2gw@pengutronix.de> (raw)
In-Reply-To: <20200109233106.17060-1-peron.clem@gmail.com>
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/ |
parent reply other threads:[~2020-01-10 7:13 UTC|newest]
Thread overview: expand[flat|nested] mbox.gz Atom feed
[parent not found: <20200109233106.17060-1-peron.clem@gmail.com>]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200110071306.uyqcyftb4bt7b2gw@pengutronix.de \
--to=u.kleine-koenig@pengutronix.de \
--cc=alex.mobigo@gmail.com \
--cc=anarsoul@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=mturquette@baylibre.com \
--cc=peron.clem@gmail.com \
--cc=sboyd@kernel.org \
--cc=thierry.reding@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).