Unverified Commit f6093339 authored by chen zhang's avatar chen zhang Committed by Ilpo Järvinen
Browse files

platform/x86: compal-laptop: use sysfs_emit() instead of sprintf()



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: default avatarchen zhang <chenzhang@kylinos.cn>
Link: https://lore.kernel.org/r/20241028024949.24746-1-chenzhang@kylinos.cn


Reviewed-by: default avatarIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: default avatarIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
parent e001341a
Loading
Loading
Loading
Loading
+29 −28
Original line number Diff line number Diff line
@@ -68,6 +68,7 @@
#include <linux/hwmon.h>
#include <linux/hwmon-sysfs.h>
#include <linux/power_supply.h>
#include <linux/sysfs.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)		\
@@ -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 */