[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <ZYAK4HaWsChgJE12@gofer.mess.org>
Date: Mon, 18 Dec 2023 09:03:28 +0000
From: Sean Young <sean@...s.org>
To: Uwe Kleine-König <u.kleine-koenig@...gutronix.de>
Cc: linux-media@...r.kernel.org, linux-pwm@...r.kernel.org,
Ivaylo Dimitrov <ivo.g.dimitrov.75@...il.com>,
Thierry Reding <thierry.reding@...il.com>,
Jonathan Corbet <corbet@....net>, linux-doc@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH v8 4/6] pwm: Make it possible to apply PWM changes in
atomic context
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
Powered by blists - more mailing lists