lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <d85ddd5d-df2c-75fe-2ec8-3444969014b3@linux.intel.com>
Date: Fri, 25 Oct 2024 18:00:00 +0300 (EEST)
From: Ilpo Järvinen <ilpo.jarvinen@...ux.intel.com>
To: chen zhang <chenzhang@...inos.cn>
cc: Hans de Goede <hdegoede@...hat.com>, cezary.jackiewicz@...il.com, 
    platform-driver-x86@...r.kernel.org, LKML <linux-kernel@...r.kernel.org>, 
    chenzhang_0901@....com
Subject: Re: [PATCH] platform/x86: compal-laptop: use sysfs_emit() instead
 of sprintf()

On Thu, 24 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@...inos.cn>
> ---
>  drivers/platform/x86/compal-laptop.c | 13 +++++++------
>  1 file changed, 7 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/platform/x86/compal-laptop.c b/drivers/platform/x86/compal-laptop.c
> index 5546fb189491..ba95f342fd59 100644
> --- a/drivers/platform/x86/compal-laptop.c
> +++ b/drivers/platform/x86/compal-laptop.c
> @@ -67,6 +67,7 @@
>  #include <linux/rfkill.h>
>  #include <linux/hwmon.h>
>  #include <linux/hwmon-sysfs.h>
> +#include <linux/sysfs.h>
>  #include <linux/power_supply.h>
>  #include <linux/fb.h>
>  #include <acpi/video.h>
> @@ -368,7 +369,7 @@ static const struct rfkill_ops compal_rfkill_ops = {
>  static ssize_t NAME##_show(struct device *dev,				\
>  	struct device_attribute *attr, char *buf)			\
>  {									\
> -	return sprintf(buf, "%d\n", ((ec_read_u8(ADDR) & MASK) != 0));	\
> +	return sysfs_emit(buf, "%d\n", ((ec_read_u8(ADDR) & MASK) != 0));	\
>  }									\
>  static ssize_t NAME##_store(struct device *dev,				\
>  	struct device_attribute *attr, const char *buf, size_t count)	\

The macro line continuation backslashes should be aligned.

--
 i.

> @@ -393,7 +394,7 @@ static ssize_t pwm_enable_show(struct device *dev,
>  		struct device_attribute *attr, char *buf)
>  {
>  	struct compal_data *data = dev_get_drvdata(dev);
> -	return sprintf(buf, "%d\n", data->pwm_enable);
> +	return sysfs_emit(buf, "%d\n", data->pwm_enable);
>  }
>  
>  static ssize_t pwm_enable_store(struct device *dev,
> @@ -432,7 +433,7 @@ static ssize_t pwm_show(struct device *dev, struct device_attribute *attr,
>  		char *buf)
>  {
>  	struct compal_data *data = dev_get_drvdata(dev);
> -	return sprintf(buf, "%hhu\n", data->curr_pwm);
> +	return sysfs_emit(buf, "%hhu\n", data->curr_pwm);
>  }
>  
>  static ssize_t pwm_store(struct device *dev, struct device_attribute *attr,
> @@ -460,7 +461,7 @@ static ssize_t pwm_store(struct device *dev, struct device_attribute *attr,
>  static ssize_t fan_show(struct device *dev, struct device_attribute *attr,
>  		char *buf)
>  {
> -	return sprintf(buf, "%d\n", get_fan_rpm());
> +	return sysfs_emit(buf, "%d\n", get_fan_rpm());
>  }
>  
>  
> @@ -469,12 +470,12 @@ static ssize_t fan_show(struct device *dev, struct device_attribute *attr,
>  static ssize_t temp_##POSTFIX(struct device *dev,			\
>  		struct device_attribute *attr, char *buf)		\
>  {									\
> -	return sprintf(buf, "%d\n", 1000 * (int)ec_read_s8(ADDRESS));	\
> +	return sysfs_emit(buf, "%d\n", 1000 * (int)ec_read_s8(ADDRESS));	\
>  }									\
>  static ssize_t label_##POSTFIX(struct device *dev,			\
>  		struct device_attribute *attr, char *buf)		\
>  {									\
> -	return sprintf(buf, "%s\n", LABEL);				\
> +	return sysfs_emit(buf, "%s\n", LABEL);				\
>  }
>  
>  /* Labels as in service guide */
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ