From: "Nuno Sá" <noname.nuno@gmail.com>
To: "Uwe Kleine-König" <u.kleine-koenig@baylibre.com>,
"David Lechner" <dlechner@baylibre.com>
Cc: linux-pwm@vger.kernel.org, Trevor Gamblin <tgamblin@baylibre.com>
Subject: Re: [PATCH v2 3/8] pwm: New abstraction for PWM waveforms
Date: Tue, 16 Jul 2024 09:29:00 +0200 [thread overview]
Message-ID: <eb1a27967dd15e15f1985ba8b0506e72bdc3f910.camel@gmail.com> (raw)
In-Reply-To: <yai3vygaf2k3udqaybn63uvokly64dfdxioyahr6g5vaj2isle@ycydrttrcvnp>
On Mon, 2024-07-15 at 22:17 +0200, Uwe Kleine-König wrote:
> Hello,
>
> On Mon, Jul 15, 2024 at 01:55:43PM -0500, David Lechner wrote:
> > On 7/15/24 6:16 AM, Uwe Kleine-König wrote:
> > > @@ -213,18 +311,60 @@ static int __pwm_apply(struct pwm_device *pwm, const
> > > struct pwm_state *state)
> > > state->usage_power == pwm->state.usage_power)
> > > return 0;
> > >
> > > - err = chip->ops->apply(chip, pwm, state);
> > > - trace_pwm_apply(pwm, state, err);
> > > - if (err)
> > > - return err;
> > > + if (ops->write_waveform) {
> > > + struct pwm_waveform wf;
> > > + char wfhw[WFHWSIZE];
> > >
> > > - pwm->state = *state;
> > > + BUG_ON(WFHWSIZE < ops->sizeof_wfhw);
> >
> > Since this is already validated in pwm_ops_check(), do we really need the
> > BUG_ON() check?
>
> It indeed should not happen, and I'm glad you seem to agree it's safe.
> The motivation to still keep it is that if (now or after some changes
> in the future) I missed a code path, it's IMHO better when the kernel
> dies on a BUG_ON (which indicates the error condition) than via some
> stack corruption some time later.
>
> > > diff --git a/include/linux/pwm.h b/include/linux/pwm.h
> > > index 464054a45e57..2a1f1f25a56c 100644
> > > --- a/include/linux/pwm.h
> > > +++ b/include/linux/pwm.h
> > > @@ -49,6 +49,30 @@ enum {
> > > PWMF_EXPORTED = 1,
> > > };
> > >
> > > +/*
> > > + * struct pwm_waveform - description of a PWM waveform
> > > + * @period_length: PWM period
> > > + * @duty_length: PWM duty cycle
> > > + * @duty_offset: offset of the rising edge from the period's start
> > > + *
> > > + * This is a representation of a PWM waveform alternative to struct
> > > pwm_state
> > > + * below. It's more expressive than struct pwm_state as it contains a
> > > + * duty_offset and so can represent offsets other than $period -
> > > $duty_cycle
> > > + * which is done using .polarity = PWM_POLARITY_INVERSED. Note there is
> > > no
> > > + * explicit bool for enabled. A "disabled" PWM is represented by .period
> > > = 0.
> > > + *
> > > + * Note that the behaviour of a "disabled" PWM is undefined. Depending on
> > > the
> > > + * hardware's capabilities it might drive the active or inactive level,
> > > go
> > > + * high-z or even continue to toggle.
> > > + *
> > > + * The unit for all three members is nanoseconds.
> > > + */
> > > +struct pwm_waveform {
> > > + u64 period_length;
> > > + u64 duty_length;
> > > + u64 duty_offset;
> > > +};
> >
> > Perhaps it would be helpful to take a hint from the IIO subsystem
> > and include the units of measurement in the field names here?
> > For example, period_length_ns or even just period_ns. This way,
> > the value is obvious even without reading the documentation.
>
> Good idea. For duty_length the "length" part is more important than for
> period_length. And indeed I wasn't sure if I should rename period at
> all. Being a fan of consistency I prefer to keep "length" also for
> period (length). But I like the _ns suffix and will rework accordingly.
>
Just as a side note. BUG_ON() usage is highly discouraged [1]... Even WARN_ON()
- which I don't agree much FWIW - is also being discouraged because of
panic_on_warn. But it actually seems that WARN* is fine but should really be
used with care.
[1]: https://docs.kernel.org/process/coding-style.html#use-warn-rather-than-bug
- Nuno Sá
next prev parent reply other threads:[~2024-07-16 7:25 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-15 11:16 [PATCH v2 0/8] pwm: New abstraction and userspace API Uwe Kleine-König
2024-07-15 11:16 ` [PATCH v2 1/8] pwm: Simplify pwm_capture() Uwe Kleine-König
2024-07-15 11:16 ` [PATCH v2 2/8] pwm: Add more locking Uwe Kleine-König
2024-07-15 16:56 ` David Lechner
2024-07-15 20:08 ` Uwe Kleine-König
2024-07-15 11:16 ` [PATCH v2 3/8] pwm: New abstraction for PWM waveforms Uwe Kleine-König
2024-07-15 18:55 ` David Lechner
2024-07-15 20:17 ` Uwe Kleine-König
2024-07-16 7:29 ` Nuno Sá [this message]
2024-07-15 11:16 ` [PATCH v2 4/8] pwm: Provide new consumer API functions for waveforms Uwe Kleine-König
2024-07-15 22:23 ` David Lechner
2024-07-16 7:06 ` Uwe Kleine-König
2024-07-16 14:28 ` David Lechner
2024-07-17 9:13 ` Uwe Kleine-König
2024-07-15 11:16 ` [PATCH v2 5/8] pwm: Add support for pwmchip devices for faster and easier userspace access Uwe Kleine-König
2024-07-15 19:37 ` David Lechner
2024-07-15 19:52 ` Uwe Kleine-König
2024-07-30 10:26 ` Uwe Kleine-König
2024-07-30 18:41 ` David Lechner
2024-07-31 6:49 ` Uwe Kleine-König
2024-07-15 11:16 ` [PATCH v2 6/8] pwm: Add tracing for waveform callbacks Uwe Kleine-König
2024-07-15 11:16 ` [PATCH v2 7/8] pwm: axi-pwmgen: Implementation of the " Uwe Kleine-König
2024-07-15 11:16 ` [PATCH v2 8/8] pwm: stm32: " Uwe Kleine-König
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=eb1a27967dd15e15f1985ba8b0506e72bdc3f910.camel@gmail.com \
--to=noname.nuno@gmail.com \
--cc=dlechner@baylibre.com \
--cc=linux-pwm@vger.kernel.org \
--cc=tgamblin@baylibre.com \
--cc=u.kleine-koenig@baylibre.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