[PATCH v1] platform/x86: classmate-laptop: Replace snprintf in show functions with sysfs_emit

Hongling Zeng posted 1 patch 1 month, 1 week ago
There is a newer version of this series
drivers/platform/x86/classmate-laptop.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
[PATCH v1] platform/x86: classmate-laptop: Replace snprintf in show functions with sysfs_emit
Posted by Hongling Zeng 1 month, 1 week ago
  show() must not use snprintf() when formatting the value to be
returned to user space.

Signed-off-by: Hongling Zeng<zenghongling@kylinos.cn>
---
 drivers/platform/x86/classmate-laptop.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/platform/x86/classmate-laptop.c b/drivers/platform/x86/classmate-laptop.c
index cb6fce6..14c238f 100644
--- a/drivers/platform/x86/classmate-laptop.c
+++ b/drivers/platform/x86/classmate-laptop.c
@@ -208,7 +208,7 @@ static ssize_t cmpc_accel_sensitivity_show_v4(struct device *dev,
 	inputdev = dev_get_drvdata(&acpi->dev);
 	accel = dev_get_drvdata(&inputdev->dev);
 
-	return sprintf(buf, "%d\n", accel->sensitivity);
+	return sysfs_emit(buf, "%d\n", accel->sensitivity);
 }
 
 static ssize_t cmpc_accel_sensitivity_store_v4(struct device *dev,
@@ -257,7 +257,7 @@ static ssize_t cmpc_accel_g_select_show_v4(struct device *dev,
 	inputdev = dev_get_drvdata(&acpi->dev);
 	accel = dev_get_drvdata(&inputdev->dev);
 
-	return sprintf(buf, "%d\n", accel->g_select);
+	return sysfs_emit(buf, "%d\n", accel->g_select);
 }
 
 static ssize_t cmpc_accel_g_select_store_v4(struct device *dev,
@@ -550,7 +550,7 @@ static ssize_t cmpc_accel_sensitivity_show(struct device *dev,
 	inputdev = dev_get_drvdata(&acpi->dev);
 	accel = dev_get_drvdata(&inputdev->dev);
 
-	return sprintf(buf, "%d\n", accel->sensitivity);
+	return sysfs_emit(buf, "%d\n", accel->sensitivity);
 }
 
 static ssize_t cmpc_accel_sensitivity_store(struct device *dev,
-- 
2.1.0
Re: [PATCH v1] platform/x86: classmate-laptop: Replace snprintf in show functions with sysfs_emit
Posted by Ilpo Järvinen 1 month ago
On Sat, 19 Oct 2024, Hongling Zeng wrote:

>   show() must not use snprintf() when formatting the value to be
> returned to user space.
> 
> Signed-off-by: Hongling Zeng <zenghongling@kylinos.cn>

Hi,

I've applied this with modifications:

- I had to cleanup the extra spaces before show() in the text above which
  I had already earlier noted you should fix. :-(
- Added #include <linux/sysfs.h>

-- 
 i.

> ---
>  drivers/platform/x86/classmate-laptop.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/platform/x86/classmate-laptop.c b/drivers/platform/x86/classmate-laptop.c
> index cb6fce6..14c238f 100644
> --- a/drivers/platform/x86/classmate-laptop.c
> +++ b/drivers/platform/x86/classmate-laptop.c
> @@ -208,7 +208,7 @@ static ssize_t cmpc_accel_sensitivity_show_v4(struct device *dev,
>  	inputdev = dev_get_drvdata(&acpi->dev);
>  	accel = dev_get_drvdata(&inputdev->dev);
>  
> -	return sprintf(buf, "%d\n", accel->sensitivity);
> +	return sysfs_emit(buf, "%d\n", accel->sensitivity);
>  }
>  
>  static ssize_t cmpc_accel_sensitivity_store_v4(struct device *dev,
> @@ -257,7 +257,7 @@ static ssize_t cmpc_accel_g_select_show_v4(struct device *dev,
>  	inputdev = dev_get_drvdata(&acpi->dev);
>  	accel = dev_get_drvdata(&inputdev->dev);
>  
> -	return sprintf(buf, "%d\n", accel->g_select);
> +	return sysfs_emit(buf, "%d\n", accel->g_select);
>  }
>  
>  static ssize_t cmpc_accel_g_select_store_v4(struct device *dev,
> @@ -550,7 +550,7 @@ static ssize_t cmpc_accel_sensitivity_show(struct device *dev,
>  	inputdev = dev_get_drvdata(&acpi->dev);
>  	accel = dev_get_drvdata(&inputdev->dev);
>  
> -	return sprintf(buf, "%d\n", accel->sensitivity);
> +	return sysfs_emit(buf, "%d\n", accel->sensitivity);
>  }
>  
>  static ssize_t cmpc_accel_sensitivity_store(struct device *dev,
>