From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: chen zhang <chenzhang@kylinos.cn>
Cc: Hans de Goede <hdegoede@redhat.com>,
cezary.jackiewicz@gmail.com,
platform-driver-x86@vger.kernel.org,
LKML <linux-kernel@vger.kernel.org>,
chenzhang_0901@163.com
Subject: Re: [PATCH] platform/x86: compal-laptop: use sysfs_emit() instead of sprintf()
Date: Fri, 25 Oct 2024 18:00:00 +0300 (EEST) [thread overview]
Message-ID: <d85ddd5d-df2c-75fe-2ec8-3444969014b3@linux.intel.com> (raw)
In-Reply-To: <20241024015605.15238-1-chenzhang@kylinos.cn>
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@kylinos.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 */
>
prev parent reply other threads:[~2024-10-25 15:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-24 1:56 [PATCH] platform/x86: compal-laptop: use sysfs_emit() instead of sprintf() chen zhang
2024-10-25 15:00 ` Ilpo Järvinen [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d85ddd5d-df2c-75fe-2ec8-3444969014b3@linux.intel.com \
--to=ilpo.jarvinen@linux.intel.com \
--cc=cezary.jackiewicz@gmail.com \
--cc=chenzhang@kylinos.cn \
--cc=chenzhang_0901@163.com \
--cc=hdegoede@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=platform-driver-x86@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.