Re: [PATCH v8 4/6] pwm: Make it possible to apply PWM changes in atomic context

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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




[Index of Archives]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]     [Linux Resources]

  Powered by Linux