[PATCH] iio: imu: inv_mpu6050: Replace scnprintf with sysfs_emit

Chelsy Ratnawat posted 1 patch 3 months, 1 week ago
There is a newer version of this series
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[PATCH] iio: imu: inv_mpu6050: Replace scnprintf with sysfs_emit
Posted by Chelsy Ratnawat 3 months, 1 week ago
Documentation/filesystems/sysfs.rst mentions that show() should only
use sysfs_emit() or sysfs_emit_at() when formating the value to be
returned to user space. So replace scnprintf() with sysfs_emit().

Signed-off-by: Chelsy Ratnawat <chelsyratnawat2001@gmail.com>
---
 drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
index b8656c02354a..53a315fd0c34 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
@@ -1382,7 +1382,7 @@ inv_fifo_rate_show(struct device *dev, struct device_attribute *attr,
 	fifo_rate = INV_MPU6050_DIVIDER_TO_FIFO_RATE(st->chip_config.divider);
 	mutex_unlock(&st->lock);
 
-	return scnprintf(buf, PAGE_SIZE, "%u\n", fifo_rate);
+	return sysfs_emit(buf, "%u\n", fifo_rate);
 }
 
 /*
@@ -1409,7 +1409,7 @@ static ssize_t inv_attr_show(struct device *dev, struct device_attribute *attr,
 	case ATTR_ACCL_MATRIX:
 		m = st->plat_data.orientation;
 
-		return scnprintf(buf, PAGE_SIZE,
+		return sysfs_emit(buf,
 			"%d, %d, %d; %d, %d, %d; %d, %d, %d\n",
 			m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7], m[8]);
 	default:
-- 
2.47.1
Re: [PATCH] iio: imu: inv_mpu6050: Replace scnprintf with sysfs_emit
Posted by Andy Shevchenko 3 months, 1 week ago
On Tue, Jul 01, 2025 at 04:39:45AM -0700, Chelsy Ratnawat wrote:
> Documentation/filesystems/sysfs.rst mentions that show() should only
> use sysfs_emit() or sysfs_emit_at() when formating the value to be
> returned to user space. So replace scnprintf() with sysfs_emit().

...

>  	case ATTR_ACCL_MATRIX:
>  		m = st->plat_data.orientation;
>  
> -		return scnprintf(buf, PAGE_SIZE,
> +		return sysfs_emit(buf,
>  			"%d, %d, %d; %d, %d, %d; %d, %d, %d\n",

Now this fits one line

		return sysfs_emit(buf, "%d, %d, %d; %d, %d, %d; %d, %d, %d\n",

>  			m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7], m[8]);

-- 
With Best Regards,
Andy Shevchenko