Linux LED subsystem development
 help / color / mirror / Atom feed
* [PATCH] leds: flash: simplify flash_fault_show()
@ 2026-09-04  5:44 Dmitry Antipov
  2026-09-04  5:53 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Dmitry Antipov @ 2026-09-04  5:44 UTC (permalink / raw)
  To: Lee Jones, Pavel Machek; +Cc: linux-leds, Dmitry Antipov

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>
---
 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 165035a8826c..1e878baff041 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, 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]);
 		mask <<= 1;
 	}
-
-	return strlen(strcat(buf, "\n"));
+	*pbuf++ = '\n';
+	*pbuf = '\0';
+	return pbuf - buf;
 }
 static DEVICE_ATTR_RO(flash_fault);
 
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-09-04  5:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-04  5:44 [PATCH] leds: flash: simplify flash_fault_show() Dmitry Antipov
2026-09-04  5:53 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox