public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] platform/x86: classmate-laptop: use sysfs_emit() instead of sprintf()
@ 2024-10-23  1:42 chen zhang
  2024-10-23 12:39 ` Ilpo Järvinen
  0 siblings, 1 reply; 2+ messages in thread
From: chen zhang @ 2024-10-23  1:42 UTC (permalink / raw)
  To: hdegoede, ilpo.jarvinen, cascardo
  Cc: platform-driver-x86, linux-kernel, chenzhang_0901, chen zhang

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

Signed-off-by: chen zhang <chenzhang@kylinos.cn>
---
v2: add #include <linux/sysfs.h>
---
 drivers/platform/x86/classmate-laptop.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/platform/x86/classmate-laptop.c b/drivers/platform/x86/classmate-laptop.c
index cb6fce655e35..6b1b8e444e24 100644
--- a/drivers/platform/x86/classmate-laptop.c
+++ b/drivers/platform/x86/classmate-laptop.c
@@ -12,6 +12,7 @@
 #include <linux/backlight.h>
 #include <linux/input.h>
 #include <linux/rfkill.h>
+#include <linux/sysfs.h>
 
 struct cmpc_accel {
 	int sensitivity;
@@ -208,7 +209,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 +258,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 +551,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.25.1


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

* Re: [PATCH v2] platform/x86: classmate-laptop: use sysfs_emit() instead of sprintf()
  2024-10-23  1:42 [PATCH v2] platform/x86: classmate-laptop: use sysfs_emit() instead of sprintf() chen zhang
@ 2024-10-23 12:39 ` Ilpo Järvinen
  0 siblings, 0 replies; 2+ messages in thread
From: Ilpo Järvinen @ 2024-10-23 12:39 UTC (permalink / raw)
  To: chen zhang
  Cc: Hans de Goede, cascardo, platform-driver-x86, LKML,
	chenzhang_0901

On Wed, 23 Oct 2024, chen zhang wrote:

> Follow the advice in Documentation/filesystems/sysfs.rst:
> show() should only use sysfs_emit() or sysfs_emit_at() when formatting
> the value to be returned to user space.
> 
> Signed-off-by: chen zhang <chenzhang@kylinos.cn>
> ---
> v2: add #include <linux/sysfs.h>
> ---
>  drivers/platform/x86/classmate-laptop.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/platform/x86/classmate-laptop.c b/drivers/platform/x86/classmate-laptop.c
> index cb6fce655e35..6b1b8e444e24 100644
> --- a/drivers/platform/x86/classmate-laptop.c
> +++ b/drivers/platform/x86/classmate-laptop.c
> @@ -12,6 +12,7 @@
>  #include <linux/backlight.h>
>  #include <linux/input.h>
>  #include <linux/rfkill.h>
> +#include <linux/sysfs.h>
>  
>  struct cmpc_accel {
>  	int sensitivity;
> @@ -208,7 +209,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 +258,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 +551,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,
> 

Hi,

Thank you for your patch, however, a similar patch (from somebody else) 
has been already applied so I dropped this one.

-- 
 i.


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

end of thread, other threads:[~2024-10-23 12:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-23  1:42 [PATCH v2] platform/x86: classmate-laptop: use sysfs_emit() instead of sprintf() chen zhang
2024-10-23 12:39 ` Ilpo Järvinen

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