[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <fol4hemfnbh7km5dfdkbrfxx3txc4wtv7jvdn4h2xlzxlcoyht@ax7ml3rq53zs>
Date: Mon, 15 Sep 2025 11:50:49 +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
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.
Best regards
Uwe
Download attachment "signature.asc" of type "application/pgp-signature" (489 bytes)
Powered by blists - more mailing lists