The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH v2] platform/x86: compal-laptop: use sysfs_emit() instead of sprintf()
@ 2024-10-28  2:49 chen zhang
  2024-10-29 15:02 ` Ilpo Järvinen
  0 siblings, 1 reply; 2+ messages in thread
From: chen zhang @ 2024-10-28  2:49 UTC (permalink / raw)
  To: hdegoede, ilpo.jarvinen, cezary.jackiewicz
  Cc: platform-driver-x86, linux-kernel, chenzhang_0901, chen zhang

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>
---
v2: The macro line continuation backslashes should be aligned.
---
 drivers/platform/x86/compal-laptop.c | 33 ++++++++++++++--------------
 1 file changed, 17 insertions(+), 16 deletions(-)

diff --git a/drivers/platform/x86/compal-laptop.c b/drivers/platform/x86/compal-laptop.c
index 5546fb189491..33e2ab2b71d1 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>
@@ -364,12 +365,12 @@ 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));	\
-}									\
+#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)	\
 {									\
@@ -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));	\
-}									\
+#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 sprintf(buf, "%s\n", LABEL);				\
+	return sysfs_emit(buf, "%s\n", LABEL);				\
 }
 
 /* Labels as in service guide */
-- 
2.25.1


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

* Re: [PATCH v2] platform/x86: compal-laptop: use sysfs_emit() instead of sprintf()
  2024-10-28  2:49 [PATCH v2] platform/x86: compal-laptop: use sysfs_emit() instead of sprintf() chen zhang
@ 2024-10-29 15:02 ` Ilpo Järvinen
  0 siblings, 0 replies; 2+ messages in thread
From: Ilpo Järvinen @ 2024-10-29 15:02 UTC (permalink / raw)
  To: hdegoede, cezary.jackiewicz, chen zhang
  Cc: platform-driver-x86, linux-kernel, chenzhang_0901

On Mon, 28 Oct 2024 10:49:49 +0800, 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.
> 
> 


Thank you for your contribution, it has been applied to my local
review-ilpo branch. Note it will show up in the public
platform-drivers-x86/review-ilpo branch only once I've pushed my
local branch there, which might take a while.

The list of commits applied:
[1/1] platform/x86: compal-laptop: use sysfs_emit() instead of sprintf()
      commit: f60933390852beb1fbbcad12df5e261cf8312a9b

--
 i.


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

end of thread, other threads:[~2024-10-29 15:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-28  2:49 [PATCH v2] platform/x86: compal-laptop: use sysfs_emit() instead of sprintf() chen zhang
2024-10-29 15:02 ` Ilpo Järvinen

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