iio: st_sensors: Convert to use sysfs_emit_at() API

Message ID 202212071553556022992@zte.com.cn
State New
Headers
Series iio: st_sensors: Convert to use sysfs_emit_at() API |

Commit Message

ye.xingchen@zte.com.cn Dec. 7, 2022, 7:53 a.m. UTC
  From: ye xingchen <ye.xingchen@zte.com.cn>

Follow the advice of the Documentation/filesystems/sysfs.rst and show()
should only use sysfs_emit() or sysfs_emit_at() when formatting the
value to be returned to user space.

Signed-off-by: ye xingchen <ye.xingchen@zte.com.cn>
---
 drivers/iio/common/st_sensors/st_sensors_core.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
  

Comments

Jonathan Cameron Dec. 11, 2022, 12:15 p.m. UTC | #1
On Wed, 7 Dec 2022 15:53:55 +0800 (CST)
<ye.xingchen@zte.com.cn> wrote:

> From: ye xingchen <ye.xingchen@zte.com.cn>
> 
> Follow the advice of the Documentation/filesystems/sysfs.rst and show()
> should only use sysfs_emit() or sysfs_emit_at() when formatting the
> value to be returned to user space.
> 
> Signed-off-by: ye xingchen <ye.xingchen@zte.com.cn>
> ---
>  drivers/iio/common/st_sensors/st_sensors_core.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/iio/common/st_sensors/st_sensors_core.c b/drivers/iio/common/st_sensors/st_sensors_core.c
> index c77d7bdcc121..44e374f84197 100644
> --- a/drivers/iio/common/st_sensors/st_sensors_core.c
> +++ b/drivers/iio/common/st_sensors/st_sensors_core.c
> @@ -628,8 +628,7 @@ ssize_t st_sensors_sysfs_sampling_frequency_avail(struct device *dev,
>  		if (sdata->sensor_settings->odr.odr_avl[i].hz == 0)
>  			break;
> 
> -		len += scnprintf(buf + len, PAGE_SIZE - len, "%d ",
> -				sdata->sensor_settings->odr.odr_avl[i].hz);
> +		len += sysfs_emit_at(buf, len, "%d ", sdata->sensor_settings->odr.odr_avl[i].hz);

Another case where I would prefer we keep the line break.

>  	}
>  	buf[len - 1] = '\n';
> 
> @@ -651,7 +650,7 @@ ssize_t st_sensors_sysfs_scale_avail(struct device *dev,
>  		q = sdata->sensor_settings->fs.fs_avl[i].gain / 1000000;
>  		r = sdata->sensor_settings->fs.fs_avl[i].gain % 1000000;
> 
> -		len += scnprintf(buf + len, PAGE_SIZE - len, "%u.%06u ", q, r);
> +		len += sysfs_emit_at(buf, len, "%u.%06u ", q, r);
>  	}
>  	buf[len - 1] = '\n';
>
  

Patch

diff --git a/drivers/iio/common/st_sensors/st_sensors_core.c b/drivers/iio/common/st_sensors/st_sensors_core.c
index c77d7bdcc121..44e374f84197 100644
--- a/drivers/iio/common/st_sensors/st_sensors_core.c
+++ b/drivers/iio/common/st_sensors/st_sensors_core.c
@@ -628,8 +628,7 @@  ssize_t st_sensors_sysfs_sampling_frequency_avail(struct device *dev,
 		if (sdata->sensor_settings->odr.odr_avl[i].hz == 0)
 			break;

-		len += scnprintf(buf + len, PAGE_SIZE - len, "%d ",
-				sdata->sensor_settings->odr.odr_avl[i].hz);
+		len += sysfs_emit_at(buf, len, "%d ", sdata->sensor_settings->odr.odr_avl[i].hz);
 	}
 	buf[len - 1] = '\n';

@@ -651,7 +650,7 @@  ssize_t st_sensors_sysfs_scale_avail(struct device *dev,
 		q = sdata->sensor_settings->fs.fs_avl[i].gain / 1000000;
 		r = sdata->sensor_settings->fs.fs_avl[i].gain % 1000000;

-		len += scnprintf(buf + len, PAGE_SIZE - len, "%u.%06u ", q, r);
+		len += sysfs_emit_at(buf, len, "%u.%06u ", q, r);
 	}
 	buf[len - 1] = '\n';