lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250618031638.26477-5-andrew.lopes@alumni.usp.br>
Date: Wed, 18 Jun 2025 00:12:19 -0300
From: Andrew Ijano <andrew.ijano@...il.com>
To: jic23@...nel.org
Cc: andrew.lopes@...mni.usp.br,
	gustavobastos@....br,
	dlechner@...libre.com,
	nuno.sa@...log.com,
	andy@...nel.org,
	jstephan@...libre.com,
	linux-iio@...r.kernel.org,
	linux-kernel@...r.kernel.org
Subject: [PATCH v6 4/4] iio: accel: sca3000: use sysfs_emit_at() instead of sprintf()

Use sysfs_emit_at() instead of sprintf() for sysfs operations as
suggested in the documentation, since it is aware of PAGE_SIZE buffer.

Signed-off-by: Andrew Ijano <andrew.lopes@...mni.usp.br>
Suggested-by: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
---
 drivers/iio/accel/sca3000.c | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)

diff --git a/drivers/iio/accel/sca3000.c b/drivers/iio/accel/sca3000.c
index 058a2d67c91c..bc0046b19511 100644
--- a/drivers/iio/accel/sca3000.c
+++ b/drivers/iio/accel/sca3000.c
@@ -423,16 +423,16 @@ sca3000_show_available_3db_freqs(struct device *dev,
 {
 	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
 	struct sca3000_state *st = iio_priv(indio_dev);
-	int len;
+	unsigned int len = 0;
 
-	len = sprintf(buf, "%d", st->info->measurement_mode_3db_freq);
+	len = sysfs_emit_at(buf, len, "%d", st->info->measurement_mode_3db_freq);
 	if (st->info->option_mode_1)
-		len += sprintf(buf + len, " %d",
+		len += sysfs_emit_at(buf, len, " %d",
 			       st->info->option_mode_1_3db_freq);
 	if (st->info->option_mode_2)
-		len += sprintf(buf + len, " %d",
+		len += sysfs_emit_at(buf, len, " %d",
 			       st->info->option_mode_2_3db_freq);
-	len += sprintf(buf + len, "\n");
+	len += sysfs_emit_at(buf, len, "\n");
 
 	return len;
 }
@@ -783,7 +783,6 @@ static ssize_t sca3000_read_av_freq(struct device *dev,
 {
 	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
 	struct sca3000_state *st = iio_priv(indio_dev);
-	unsigned int len = 0;
 	int ret;
 
 	scoped_guard(mutex, &st->lock) {
@@ -794,25 +793,22 @@ static ssize_t sca3000_read_av_freq(struct device *dev,
 
 	switch (ret & SCA3000_REG_MODE_MODE_MASK) {
 	case SCA3000_REG_MODE_MEAS_MODE_NORMAL:
-		len += sprintf(buf + len, "%d %d %d\n",
+		return sysfs_emit(buf, "%d %d %d\n",
 			       st->info->measurement_mode_freq,
 			       st->info->measurement_mode_freq / 2,
 			       st->info->measurement_mode_freq / 4);
-		break;
 	case SCA3000_REG_MODE_MEAS_MODE_OP_1:
-		len += sprintf(buf + len, "%d %d %d\n",
+		return sysfs_emit(buf, "%d %d %d\n",
 			       st->info->option_mode_1_freq,
 			       st->info->option_mode_1_freq / 2,
 			       st->info->option_mode_1_freq / 4);
-		break;
 	case SCA3000_REG_MODE_MEAS_MODE_OP_2:
-		len += sprintf(buf + len, "%d %d %d\n",
+		return sysfs_emit(buf, "%d %d %d\n",
 			       st->info->option_mode_2_freq,
 			       st->info->option_mode_2_freq / 2,
 			       st->info->option_mode_2_freq / 4);
-		break;
 	}
-	return len;
+	return 0;
 }
 
 /*
-- 
2.49.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ