All of lore.kernel.org
 help / color / mirror / Atom feed
From: Brian Norris <briannorris@chromium.org>
To: Boris Brezillon <boris.brezillon@free-electrons.com>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>,
	Thierry Reding <thierry.reding@gmail.com>,
	Linux PWM List <linux-pwm@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Brian Norris <computersforpeace@gmail.com>,
	Doug Anderson <dianders@chromium.org>,
	linux-renesas-soc@vger.kernel.org,
	Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Subject: Re: [PATCH v2] pwm: improve args checking in pwm_apply_state()
Date: Wed, 22 Jun 2016 12:16:59 -0700	[thread overview]
Message-ID: <20160622191658.GA106497@google.com> (raw)
In-Reply-To: <20160622100422.5c34f975@bbrezillon>

On Wed, Jun 22, 2016 at 10:04:22AM +0200, Boris Brezillon wrote:
> From 0610f7e24976e176054bce20445ff42d8aea9513 Mon Sep 17 00:00:00 2001
> From: Boris Brezillon <boris.brezillon@free-electrons.com>
> Date: Wed, 22 Jun 2016 09:25:14 +0200
> Subject: [PATCH] pwm: Fix pwm_apply_args()
> 
> Commit 5ec803edcb70 ("pwm: Add core infrastructure to allow atomic
> updates"), implemented pwm_disable() as a wrapper around
> pwm_apply_state(), and then, commit ef2bf4997f7d ("pwm: Improve args
> checking in pwm_apply_state()") added missing checks on the ->period
> value in pwm_apply_state() to ensure we were not passing inappropriate
> values to the ->config() or ->apply() methods.
> 
> The conjunction of these 2 commits led to a case where pwm_disable()
> was no longer succeeding, thus preventing the polarity setting done
> in pwm_apply_args().
> 
> Set a valid period in pwm_apply_args() to ensure polarity setting
> won't be rejected.
> 
> Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
> Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
> Suggested-by: Brian Norris <briannorris@chromium.org>
> Fixes: 5ec803edcb70 ("pwm: Add core infrastructure to allow atomic updates")
> ---
>  include/linux/pwm.h | 16 ++++++++++------
>  1 file changed, 10 insertions(+), 6 deletions(-)
> 
> diff --git a/include/linux/pwm.h b/include/linux/pwm.h
> index 908b67c847cd..c038ae36b10e 100644
> --- a/include/linux/pwm.h
> +++ b/include/linux/pwm.h
> @@ -464,6 +464,8 @@ static inline bool pwm_can_sleep(struct pwm_device *pwm)
>  
>  static inline void pwm_apply_args(struct pwm_device *pwm)
>  {
> +	struct pwm_state state = { };
> +
>  	/*
>  	 * PWM users calling pwm_apply_args() expect to have a fresh config
>  	 * where the polarity and period are set according to pwm_args info.
> @@ -476,18 +478,20 @@ static inline void pwm_apply_args(struct pwm_device *pwm)
>  	 * at startup (even if they are actually enabled), thus authorizing
>  	 * polarity setting.
>  	 *
> -	 * Instead of setting ->enabled to false, we call pwm_disable()
> -	 * before pwm_set_polarity() to ensure that everything is configured
> -	 * as expected, and the PWM is really disabled when the user request
> -	 * it.

I was confused by this original text when reading it the first time. I
like the replacement text and implementation, as it seems to make more
sense.

> +	 * To fulfill this requirement, we apply a new state which disables
> +	 * the PWM device and set the reference period and polarity config.
>  	 *
>  	 * Note that PWM users requiring a smooth handover between the
>  	 * bootloader and the kernel (like critical regulators controlled by
>  	 * PWM devices) will have to switch to the atomic API and avoid calling
>  	 * pwm_apply_args().
>  	 */
> -	pwm_disable(pwm);
> -	pwm_set_polarity(pwm, pwm->args.polarity);

Notably, you're dropping the 'if (!pwm) { }' safety checks that are part
of pwm_disable() and pwm_set_polarity(). But I don't think there should
be any users relying on that.

> +
> +	state.enabled = false;
> +	state.polarity = pwm->args.polarity;
> +	state.period = pwm->args.period;
> +
> +	pwm_apply_state(pwm, &state);
>  }
>  
>  struct pwm_lookup {

Reviewed-by: Brian Norris <briannorris@chromium.org>

  parent reply	other threads:[~2016-06-22 19:17 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-27 16:45 [PATCH v2] pwm: improve args checking in pwm_apply_state() Brian Norris
2016-05-27 16:45 ` Brian Norris
2016-05-27 16:54 ` Boris Brezillon
2016-05-27 16:54   ` Boris Brezillon
2016-06-10 12:20 ` Thierry Reding
2016-06-21 14:42 ` Geert Uytterhoeven
2016-06-21 18:37   ` Brian Norris
2016-06-21 18:37     ` Brian Norris
2016-06-21 21:22     ` Boris Brezillon
2016-06-22  8:04     ` Boris Brezillon
2016-06-22  8:04       ` Boris Brezillon
2016-06-22 12:00       ` Thierry Reding
2016-06-22 14:32       ` Geert Uytterhoeven
2016-06-22 19:16       ` Brian Norris [this message]
2016-06-22 20:41         ` Boris Brezillon
2016-06-22 20:46           ` Brian Norris
2016-06-23 16:55             ` Thierry Reding

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=20160622191658.GA106497@google.com \
    --to=briannorris@chromium.org \
    --cc=boris.brezillon@free-electrons.com \
    --cc=computersforpeace@gmail.com \
    --cc=dianders@chromium.org \
    --cc=geert@linux-m68k.org \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=linux-renesas-soc@vger.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 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.