Linux IIO development
 help / color / mirror / Atom feed
* [PATCH v3] iio: light: tsl2583: migrate to sysfs_emit() and sysfs_emit_at()
@ 2026-07-16  1:04 OrangeBlack0765
  2026-07-16 20:12 ` Andy Shevchenko
  0 siblings, 1 reply; 3+ messages in thread
From: OrangeBlack0765 @ 2026-07-16  1:04 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: Andy Shevchenko, linux-iio, linux-kernel, Chengrui Liu

From: Chengrui Liu <OrangeBlack0765@outlook.com>

Replace sprintf() with sysfs_emit() for single-value sysfs show
functions, and use sysfs_emit_at() for lux_table_show() which
concatenates multiple values. This ensures buffer safety and
follows the modern kernel sysfs API.

Signed-off-by: Chengrui Liu <OrangeBlack0765@outlook.com>
---
Changes in v3:
- Use tab-only indentation for multi-line function arguments to pass checkpatch.pl

 drivers/iio/light/tsl2583.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/iio/light/tsl2583.c b/drivers/iio/light/tsl2583.c
index a0dd122af..a210d87a1 100644
--- a/drivers/iio/light/tsl2583.c
+++ b/drivers/iio/light/tsl2583.c
@@ -475,7 +475,7 @@ static ssize_t in_illuminance_input_target_show(struct device *dev,
 	int ret;
 
 	mutex_lock(&chip->als_mutex);
-	ret = sprintf(buf, "%d\n", chip->als_settings.als_cal_target);
+	ret = sysfs_emit(buf, "%d\n", chip->als_settings.als_cal_target);
 	mutex_unlock(&chip->als_mutex);
 
 	return ret;
@@ -533,10 +533,10 @@ static ssize_t in_illuminance_lux_table_show(struct device *dev,
 	int offset = 0;
 
 	for (i = 0; i < ARRAY_SIZE(chip->als_settings.als_device_lux); i++) {
-		offset += sprintf(buf + offset, "%u,%u,%u,",
-				  chip->als_settings.als_device_lux[i].ratio,
-				  chip->als_settings.als_device_lux[i].ch0,
-				  chip->als_settings.als_device_lux[i].ch1);
+		offset += sysfs_emit_at(buf, offset, "%u,%u,%u,",
+					chip->als_settings.als_device_lux[i].ratio,
+					chip->als_settings.als_device_lux[i].ch0,
+					chip->als_settings.als_device_lux[i].ch1);
 		if (chip->als_settings.als_device_lux[i].ratio == 0) {
 			/*
 			 * We just printed the first "0" entry.
@@ -547,7 +547,7 @@ static ssize_t in_illuminance_lux_table_show(struct device *dev,
 		}
 	}
 
-	offset += sprintf(buf + offset, "\n");
+	offset += sysfs_emit_at(buf, offset, "\n");
 
 	return offset;
 }
-- 
2.53.0


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

end of thread, other threads:[~2026-07-20  1:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-16  1:04 [PATCH v3] iio: light: tsl2583: migrate to sysfs_emit() and sysfs_emit_at() OrangeBlack0765
2026-07-16 20:12 ` Andy Shevchenko
2026-07-20  1:51   ` Jonathan Cameron

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