Re: [PATCH] pwm: use str_plural() to simplify the code

From: Uwe Kleine-König

Date: Fri Sep 26 2025 - 13:13:03 EST


Hello,

On Mon, Sep 15, 2025 at 11:50:49AM +0200, Uwe Kleine-König wrote:
> On Mon, Aug 18, 2025 at 04:36:29PM +0800, Xichao Zhao wrote:
> > Use the string choice helper function str_plural() to simplify the code.
> >
> > Signed-off-by: Xichao Zhao <zhao.xichao@xxxxxxxx>
> > ---
> > drivers/pwm/core.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
> > index 0d66376a83ec..732d22dee035 100644
> > --- a/drivers/pwm/core.c
> > +++ b/drivers/pwm/core.c
> > @@ -2620,7 +2620,7 @@ static int pwm_seq_show(struct seq_file *s, void *v)
> > (char *)s->private, chip->id,
> > pwmchip_parent(chip)->bus ? pwmchip_parent(chip)->bus->name : "no-bus",
> > dev_name(pwmchip_parent(chip)), chip->npwm,
> > - (chip->npwm != 1) ? "s" : "");
> > + str_plural(chip->npwm));
> >
> > pwm_dbg_show(chip, s);
>
> I'm not sure this is an improvement. While the code is shorter and might
> compile to more efficient code, it's also less readable.
>
> I tend to do just
>
> diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
> index ea2ccf42e814..5b75f4a08496 100644
> --- a/drivers/pwm/core.c
> +++ b/drivers/pwm/core.c
> @@ -2696,11 +2696,10 @@ static int pwm_seq_show(struct seq_file *s, void *v)
> {
> struct pwm_chip *chip = v;
>
> - seq_printf(s, "%s%d: %s/%s, %d PWM device%s\n",
> + seq_printf(s, "%s%d: %s/%s, npwm: %d\n",
> (char *)s->private, chip->id,
> pwmchip_parent(chip)->bus ? pwmchip_parent(chip)->bus->name : "no-bus",
> - dev_name(pwmchip_parent(chip)), chip->npwm,
> - (chip->npwm != 1) ? "s" : "");
> + dev_name(pwmchip_parent(chip)), chip->npwm);
>
> pwm_dbg_show(chip, s);
>
> instead, or drop the output of npwm completely given its value
> implicitly clear by the number of lines following this output.

FTR: I submitted a patch implementing this suggestion now and
accordingly will mark the converstion to str_plural (i.e. the original
patch of this thread) as superseded.

Best regards
Uwe

Attachment: signature.asc
Description: PGP signature