public inbox for linux-pwm@vger.kernel.org
 help / color / mirror / Atom feed
From: Sean Young <sean@mess.org>
To: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Cc: linux-media@vger.kernel.org, linux-pwm@vger.kernel.org,
	Ivaylo Dimitrov <ivo.g.dimitrov.75@gmail.com>,
	Thierry Reding <thierry.reding@gmail.com>,
	Jonathan Corbet <corbet@lwn.net>,
	linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v8 4/6] pwm: Make it possible to apply PWM changes in atomic context
Date: Mon, 18 Dec 2023 09:03:28 +0000	[thread overview]
Message-ID: <ZYAK4HaWsChgJE12@gofer.mess.org> (raw)
In-Reply-To: <20231212114812.afzgjiunzc6druov@pengutronix.de>

Hello Uwe,

On Tue, Dec 12, 2023 at 12:48:12PM +0100, Uwe Kleine-König wrote:
> On Tue, Dec 12, 2023 at 08:34:03AM +0000, Sean Young wrote:
> > +/**
> > + * pwm_apply_might_sleep() - atomically apply a new state to a PWM device
> > + * Cannot be used in atomic context.
> > + * @pwm: PWM device
> > + * @state: new state to apply
> > + */
> > +int pwm_apply_might_sleep(struct pwm_device *pwm, const struct pwm_state *state)
> > +{
> > +	int err;
> > +
> > +	/*
> > +	 * Some lowlevel driver's implementations of .apply() make use of
> > +	 * mutexes, also with some drivers only returning when the new
> > +	 * configuration is active calling pwm_apply_might_sleep() from atomic context
> > +	 * is a bad idea. So make it explicit that calling this function might
> > +	 * sleep.
> > +	 */
> > +	might_sleep();
> > +
> > +	if (IS_ENABLED(CONFIG_PWM_DEBUG) && pwm->chip->atomic) {
> > +		/*
> > +		 * Catch any drivers that have been marked as atomic but
> > +		 * that will sleep anyway.
> > +		 */
> > +		non_block_start();
> > +		err = pwm_apply_unchecked(pwm, state);
> > +		non_block_end();
> > +	} else {
> > +		err = pwm_apply_unchecked(pwm, state);
> > +	}
> > +
> >  	/*
> >  	 * only do this after pwm->state was applied as some
> >  	 * implementations of .get_state depend on this
> >  	 */
> > -	pwm_apply_debug(pwm, state);
> > +	if (!err)
> > +		pwm_apply_debug(pwm, state);
> 
> It's easier to keep that in pwm_apply_unchecked(), isn't it? Then
> pwm_apply_atomic() also benefits from the checks.

Good point.

> I'm not so happy with the function name of pwm_apply_unchecked(), but I
> don't have a good suggestion either. Probably I'd have chosen
> __pam_apply(), but that's probably subjective.

That is more consistent, fixed in v9.


Sean

  reply	other threads:[~2023-12-18  9:03 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-12  8:33 [PATCH v8 0/6] Improve pwm-ir-tx precision Sean Young
2023-12-12  8:34 ` [PATCH v8 1/6] pwm: Rename pwm_apply_state() to pwm_apply_might_sleep() Sean Young
2023-12-12 11:41   ` Uwe Kleine-König
2023-12-12 15:22     ` Guenter Roeck
2023-12-12 15:27       ` Mark Brown
2023-12-12  8:34 ` [PATCH v8 2/6] pwm: Replace ENOTSUPP with EOPNOTSUPP Sean Young
2023-12-12 11:31   ` Uwe Kleine-König
2023-12-12  8:34 ` [PATCH v8 3/6] pwm: renesas: Remove unused include Sean Young
2023-12-12 11:28   ` Uwe Kleine-König
2023-12-12  8:34 ` [PATCH v8 4/6] pwm: Make it possible to apply PWM changes in atomic context Sean Young
2023-12-12 11:48   ` Uwe Kleine-König
2023-12-18  9:03     ` Sean Young [this message]
2023-12-12  8:34 ` [PATCH v8 5/6] pwm: bcm2835: Allow PWM driver to be used " Sean Young
2023-12-12 11:50   ` Uwe Kleine-König
2023-12-12 16:08   ` Uwe Kleine-König
2023-12-12 16:11     ` Florian Fainelli
2023-12-12 18:14     ` Uwe Kleine-König
2023-12-18  9:02       ` Sean Young
2023-12-18  9:02     ` Sean Young
2023-12-12  8:34 ` [PATCH v8 6/6] media: pwm-ir-tx: Trigger edges from hrtimer interrupt context Sean Young

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=ZYAK4HaWsChgJE12@gofer.mess.org \
    --to=sean@mess.org \
    --cc=corbet@lwn.net \
    --cc=ivo.g.dimitrov.75@gmail.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=thierry.reding@gmail.com \
    --cc=u.kleine-koenig@pengutronix.de \
    /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