Re: [PATCH] platform/x86: compal-laptop: use sysfs_emit() instead of sprintf()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
> ---
>  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 */
> 




[Index of Archives]     [Linux Kernel Development]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux