From: Lee Jones <lee@kernel.org>
To: Dmitry Antipov <dmantipov@yandex.ru>
Cc: Pavel Machek <pavel@kernel.org>, linux-leds@vger.kernel.org
Subject: Re: [PATCH v2 2/2] leds: flash: Simplify flash_fault_show()
Date: Wed, 16 Sep 2026 16:01:15 +0100 [thread overview]
Message-ID: <20260916150115.GE1605367@google.com> (raw)
In-Reply-To: <20260904070806.19125-2-dmantipov@yandex.ru>
On Fri, 04 Sep 2026, Dmitry Antipov wrote:
> Do not emit extra trailing space and prefer direct pointer
> ops over strcat() and strlen() calls in flash_fault_show().
>
> Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
> ---
> v2: capitalize commit title
> ---
> drivers/leds/led-class-flash.c | 18 ++++++++----------
> 1 file changed, 8 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/leds/led-class-flash.c b/drivers/leds/led-class-flash.c
> index 3bb90823de1a..d09c71fcd2b3 100644
> --- a/drivers/leds/led-class-flash.c
> +++ b/drivers/leds/led-class-flash.c
> @@ -189,24 +189,22 @@ static ssize_t flash_fault_show(struct device *dev,
> struct led_classdev_flash *fled_cdev = lcdev_to_flcdev(led_cdev);
> u32 fault = 0, mask = 0x1;
> char *pbuf = buf;
> - int i, ret, buf_len;
> + int i, ret;
>
> ret = led_get_flash_fault(fled_cdev, &fault);
> if (ret < 0)
> return -EINVAL;
>
> - *buf = '\0';
> -
> for (i = 0; i < LED_NUM_FLASH_FAULTS; ++i) {
> - if (fault & mask) {
> - buf_len = sprintf(pbuf, "%s ",
> - led_flash_fault_names[i]);
> - pbuf += buf_len;
> - }
> + if (fault & mask)
> + pbuf += sprintf(pbuf, "%s%s",
> + (pbuf == buf ? "" : " "),
> + led_flash_fault_names[i]);
Shouldn't this be sysfs_emit_at() now?
> mask <<= 1;
> }
> -
> - return strlen(strcat(buf, "\n"));
> + *pbuf++ = '\n';
> + *pbuf = '\0';
> + return pbuf - buf;
> }
sysfs_emit_at() would also avoid some of this dancing around, I think.
> static DEVICE_ATTR_RO(flash_fault);
>
> --
> 2.55.0
>
>
--
Lee Jones
next prev parent reply other threads:[~2026-09-16 15:01 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-04 7:08 [PATCH v2 1/2] leds: flash: Prevent using uninitialized variable in flash_fault_show() Dmitry Antipov
2026-09-04 7:08 ` [PATCH v2 2/2] leds: flash: Simplify flash_fault_show() Dmitry Antipov
2026-09-04 7:11 ` sashiko-bot
2026-09-16 15:01 ` Lee Jones [this message]
2026-09-04 7:21 ` [PATCH v2 1/2] leds: flash: Prevent using uninitialized variable in flash_fault_show() sashiko-bot
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=20260916150115.GE1605367@google.com \
--to=lee@kernel.org \
--cc=dmantipov@yandex.ru \
--cc=linux-leds@vger.kernel.org \
--cc=pavel@kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.