[PATCH] leds: led-class: Replace sprintf with sysfs_emit in sysfs show functions

Thorsten Blum posted 1 patch 3 months ago
drivers/leds/led-class.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
[PATCH] leds: led-class: Replace sprintf with sysfs_emit in sysfs show functions
Posted by Thorsten Blum 3 months ago
Replace sprintf() with sysfs_emit() in sysfs show functions.
sysfs_emit() is preferred to format sysfs output as it provides better
bounds checking.  No functional changes.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
 drivers/leds/led-class.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
index f3faf37f9a08..885399ed0776 100644
--- a/drivers/leds/led-class.c
+++ b/drivers/leds/led-class.c
@@ -38,7 +38,7 @@ static ssize_t brightness_show(struct device *dev,
 	brightness = led_cdev->brightness;
 	mutex_unlock(&led_cdev->led_access);
 
-	return sprintf(buf, "%u\n", brightness);
+	return sysfs_emit(buf, "%u\n", brightness);
 }
 
 static ssize_t brightness_store(struct device *dev,
@@ -80,7 +80,7 @@ static ssize_t max_brightness_show(struct device *dev,
 	max_brightness = led_cdev->max_brightness;
 	mutex_unlock(&led_cdev->led_access);
 
-	return sprintf(buf, "%u\n", max_brightness);
+	return sysfs_emit(buf, "%u\n", max_brightness);
 }
 static DEVICE_ATTR_RO(max_brightness);
 
@@ -122,7 +122,7 @@ static ssize_t brightness_hw_changed_show(struct device *dev,
 	if (led_cdev->brightness_hw_changed == -1)
 		return -ENODATA;
 
-	return sprintf(buf, "%u\n", led_cdev->brightness_hw_changed);
+	return sysfs_emit(buf, "%u\n", led_cdev->brightness_hw_changed);
 }
 
 static DEVICE_ATTR_RO(brightness_hw_changed);
-- 
2.51.1
Re: (subset) [PATCH] leds: led-class: Replace sprintf with sysfs_emit in sysfs show functions
Posted by Lee Jones 2 months, 3 weeks ago
On Mon, 03 Nov 2025 13:08:09 +0100, Thorsten Blum wrote:
> Replace sprintf() with sysfs_emit() in sysfs show functions.
> sysfs_emit() is preferred to format sysfs output as it provides better
> bounds checking.  No functional changes.
> 
> 

Applied, thanks!

[1/1] leds: led-class: Replace sprintf with sysfs_emit in sysfs show functions
      commit: 92f4b016dcb955cc0bb3942ac217cff6fe450a57

--
Lee Jones [李琼斯]