[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <e6nqcot2ju4teuencgy52tce6xapstocxu6jtxeu2qaua7d5hg@mxszv6lfqsxt>
Date: Fri, 26 Sep 2025 19:13:01 +0200
From: Uwe Kleine-König <ukleinek@...nel.org>
To: Xichao Zhao <zhao.xichao@...o.com>
Cc: linux-pwm@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] pwm: use str_plural() to simplify the code
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@...o.com>
> > ---
> > 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
Download attachment "signature.asc" of type "application/pgp-signature" (489 bytes)
Powered by blists - more mailing lists