public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1] platform/x86: asus-wmi: use sysfs_emit() instead of sprintf()
@ 2024-03-19  5:56 Ai Chao
  2024-03-25 14:42 ` Hans de Goede
  0 siblings, 1 reply; 2+ messages in thread
From: Ai Chao @ 2024-03-19  5:56 UTC (permalink / raw)
  To: corentin.chary, luke, hdegoede, ilpo.jarvinen,
	platform-driver-x86, linux-kernel
  Cc: Ai Chao

This changes all *_show attributes in asus-wmi.c to use sysfs_emit()
instead of the older method of writing to the output buffer manually.

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: Ai Chao <aichao@kylinos.cn>
---
 drivers/platform/x86/asus-wmi.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
index 3f07bbf809ef..df4c103459da 100644
--- a/drivers/platform/x86/asus-wmi.c
+++ b/drivers/platform/x86/asus-wmi.c
@@ -2326,7 +2326,7 @@ static ssize_t pwm1_show(struct device *dev,
 
 	/* If we already set a value then just return it */
 	if (asus->agfn_pwm >= 0)
-		return sprintf(buf, "%d\n", asus->agfn_pwm);
+		return sysfs_emit(buf, "%d\n", asus->agfn_pwm);
 
 	/*
 	 * If we haven't set already set a value through the AGFN interface,
@@ -2512,8 +2512,8 @@ static ssize_t asus_hwmon_temp1(struct device *dev,
 	if (err < 0)
 		return err;
 
-	return sprintf(buf, "%ld\n",
-		       deci_kelvin_to_millicelsius(value & 0xFFFF));
+	return sysfs_emit(buf, "%ld\n",
+			  deci_kelvin_to_millicelsius(value & 0xFFFF));
 }
 
 /* GPU fan on modern ROG laptops */
@@ -4061,7 +4061,7 @@ static ssize_t show_sys_wmi(struct asus_wmi *asus, int devid, char *buf)
 	if (value < 0)
 		return value;
 
-	return sprintf(buf, "%d\n", value);
+	return sysfs_emit(buf, "%d\n", value);
 }
 
 #define ASUS_WMI_CREATE_DEVICE_ATTR(_name, _mode, _cm)			\
-- 
2.25.1


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

* Re: [PATCH v1] platform/x86: asus-wmi: use sysfs_emit() instead of sprintf()
  2024-03-19  5:56 [PATCH v1] platform/x86: asus-wmi: use sysfs_emit() instead of sprintf() Ai Chao
@ 2024-03-25 14:42 ` Hans de Goede
  0 siblings, 0 replies; 2+ messages in thread
From: Hans de Goede @ 2024-03-25 14:42 UTC (permalink / raw)
  To: Ai Chao, corentin.chary, luke, ilpo.jarvinen, platform-driver-x86,
	linux-kernel

Hi,

On 3/19/24 6:56 AM, Ai Chao wrote:
> This changes all *_show attributes in asus-wmi.c to use sysfs_emit()
> instead of the older method of writing to the output buffer manually.
> 
> 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: Ai Chao <aichao@kylinos.cn>

Thank you for your patch, I've applied this patch to my review-hans 
branch:
https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=review-hans

Note it will show up in my review-hans branch once I've pushed my
local branch there, which might take a while.

Once I've run some tests on this branch the patches there will be
added to the platform-drivers-x86/for-next branch and eventually
will be included in the pdx86 pull-request to Linus for the next
merge-window.

Regards,

Hans



> ---
>  drivers/platform/x86/asus-wmi.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
> index 3f07bbf809ef..df4c103459da 100644
> --- a/drivers/platform/x86/asus-wmi.c
> +++ b/drivers/platform/x86/asus-wmi.c
> @@ -2326,7 +2326,7 @@ static ssize_t pwm1_show(struct device *dev,
>  
>  	/* If we already set a value then just return it */
>  	if (asus->agfn_pwm >= 0)
> -		return sprintf(buf, "%d\n", asus->agfn_pwm);
> +		return sysfs_emit(buf, "%d\n", asus->agfn_pwm);
>  
>  	/*
>  	 * If we haven't set already set a value through the AGFN interface,
> @@ -2512,8 +2512,8 @@ static ssize_t asus_hwmon_temp1(struct device *dev,
>  	if (err < 0)
>  		return err;
>  
> -	return sprintf(buf, "%ld\n",
> -		       deci_kelvin_to_millicelsius(value & 0xFFFF));
> +	return sysfs_emit(buf, "%ld\n",
> +			  deci_kelvin_to_millicelsius(value & 0xFFFF));
>  }
>  
>  /* GPU fan on modern ROG laptops */
> @@ -4061,7 +4061,7 @@ static ssize_t show_sys_wmi(struct asus_wmi *asus, int devid, char *buf)
>  	if (value < 0)
>  		return value;
>  
> -	return sprintf(buf, "%d\n", value);
> +	return sysfs_emit(buf, "%d\n", value);
>  }
>  
>  #define ASUS_WMI_CREATE_DEVICE_ATTR(_name, _mode, _cm)			\


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

end of thread, other threads:[~2024-03-25 14:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-19  5:56 [PATCH v1] platform/x86: asus-wmi: use sysfs_emit() instead of sprintf() Ai Chao
2024-03-25 14:42 ` Hans de Goede

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