]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
platform/x86: compal-laptop: use sysfs_emit() instead of sprintf()
authorchen zhang <chenzhang@kylinos.cn>
Mon, 28 Oct 2024 02:49:49 +0000 (10:49 +0800)
committerIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Tue, 29 Oct 2024 13:54:41 +0000 (15:54 +0200)
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>
Link: https://lore.kernel.org/r/20241028024949.24746-1-chenzhang@kylinos.cn
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
drivers/platform/x86/compal-laptop.c

index 4e1d44670bd101c5211119330d51d4d377fc9fc7..58754bc5b5b1751c4d77b5b3de57535fe8ba1050 100644 (file)
@@ -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>
 
@@ -364,21 +365,21 @@ static const struct rfkill_ops compal_rfkill_ops = {
 
 
 /* Wake_up interface */
-#define SIMPLE_MASKED_STORE_SHOW(NAME, ADDR, MASK)                     \
-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));  \
-}                                                                      \
-static ssize_t NAME##_store(struct device *dev,                                \
-       struct device_attribute *attr, const char *buf, size_t count)   \
-{                                                                      \
-       int state;                                                      \
-       u8 old_val = ec_read_u8(ADDR);                                  \
-       if (sscanf(buf, "%d", &state) != 1 || (state < 0 || state > 1)) \
-               return -EINVAL;                                         \
-       ec_write(ADDR, state ? (old_val | MASK) : (old_val & ~MASK));   \
-       return count;                                                   \
+#define SIMPLE_MASKED_STORE_SHOW(NAME, ADDR, MASK)                             \
+static ssize_t NAME##_show(struct device *dev,                                 \
+       struct device_attribute *attr, char *buf)                               \
+{                                                                              \
+       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)           \
+{                                                                              \
+       int state;                                                              \
+       u8 old_val = ec_read_u8(ADDR);                                          \
+       if (sscanf(buf, "%d", &state) != 1 || (state < 0 || state > 1))         \
+               return -EINVAL;                                                 \
+       ec_write(ADDR, state ? (old_val | MASK) : (old_val & ~MASK));           \
+       return count;                                                           \
 }
 
 SIMPLE_MASKED_STORE_SHOW(wake_up_pme,  WAKE_UP_ADDR, WAKE_UP_PME)
@@ -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,21 +461,21 @@ 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());
 }
 
 
 /* Temperature interface */
-#define TEMPERATURE_SHOW_TEMP_AND_LABEL(POSTFIX, ADDRESS, LABEL)       \
-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));   \
-}                                                                      \
-static ssize_t label_##POSTFIX(struct device *dev,                     \
-               struct device_attribute *attr, char *buf)               \
-{                                                                      \
-       return sprintf(buf, "%s\n", LABEL);                             \
+#define TEMPERATURE_SHOW_TEMP_AND_LABEL(POSTFIX, ADDRESS, LABEL)               \
+static ssize_t temp_##POSTFIX(struct device *dev,                              \
+               struct device_attribute *attr, char *buf)                       \
+{                                                                              \
+       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 sysfs_emit(buf, "%s\n", LABEL);                                  \
 }
 
 /* Labels as in service guide */