Commit 256b734e authored by ye xingchen's avatar ye xingchen Committed by Tzung-Bi Shih

platform/chrome: use sysfs_emit() instead of scnprintf()

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 avatarye xingchen <ye.xingchen@zte.com.cn>
Link: https://lore.kernel.org/r/202212021656040995199@zte.com.cn
[tzungbi: fixed the commit message.]
Signed-off-by: default avatarTzung-Bi Shih <tzungbi@kernel.org>
parent 1b929c02
...@@ -34,7 +34,7 @@ static ssize_t interval_msec_show(struct device *dev, ...@@ -34,7 +34,7 @@ static ssize_t interval_msec_show(struct device *dev,
{ {
unsigned long msec = lb_interval_jiffies * 1000 / HZ; unsigned long msec = lb_interval_jiffies * 1000 / HZ;
return scnprintf(buf, PAGE_SIZE, "%lu\n", msec); return sysfs_emit(buf, "%lu\n", msec);
} }
static ssize_t interval_msec_store(struct device *dev, static ssize_t interval_msec_store(struct device *dev,
...@@ -169,7 +169,7 @@ static ssize_t version_show(struct device *dev, ...@@ -169,7 +169,7 @@ static ssize_t version_show(struct device *dev,
if (!get_lightbar_version(ec, &version, &flags)) if (!get_lightbar_version(ec, &version, &flags))
return -EIO; return -EIO;
return scnprintf(buf, PAGE_SIZE, "%d %d\n", version, flags); return sysfs_emit(buf, "%d %d\n", version, flags);
} }
static ssize_t brightness_store(struct device *dev, static ssize_t brightness_store(struct device *dev,
...@@ -302,17 +302,15 @@ static ssize_t sequence_show(struct device *dev, ...@@ -302,17 +302,15 @@ static ssize_t sequence_show(struct device *dev,
ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg); ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
if (ret < 0) { if (ret < 0) {
ret = scnprintf(buf, PAGE_SIZE, "XFER / EC ERROR %d / %d\n", ret = sysfs_emit(buf, "XFER / EC ERROR %d / %d\n", ret, msg->result);
ret, msg->result);
goto exit; goto exit;
} }
resp = (struct ec_response_lightbar *)msg->data; resp = (struct ec_response_lightbar *)msg->data;
if (resp->get_seq.num >= ARRAY_SIZE(seqname)) if (resp->get_seq.num >= ARRAY_SIZE(seqname))
ret = scnprintf(buf, PAGE_SIZE, "%d\n", resp->get_seq.num); ret = sysfs_emit(buf, "%d\n", resp->get_seq.num);
else else
ret = scnprintf(buf, PAGE_SIZE, "%s\n", ret = sysfs_emit(buf, "%s\n", seqname[resp->get_seq.num]);
seqname[resp->get_seq.num]);
exit: exit:
kfree(msg); kfree(msg);
...@@ -483,7 +481,7 @@ static ssize_t userspace_control_show(struct device *dev, ...@@ -483,7 +481,7 @@ static ssize_t userspace_control_show(struct device *dev,
struct device_attribute *attr, struct device_attribute *attr,
char *buf) char *buf)
{ {
return scnprintf(buf, PAGE_SIZE, "%d\n", userspace_control); return sysfs_emit(buf, "%d\n", userspace_control);
} }
static ssize_t userspace_control_store(struct device *dev, static ssize_t userspace_control_store(struct device *dev,
......
...@@ -227,7 +227,7 @@ static ssize_t flashinfo_show(struct device *dev, ...@@ -227,7 +227,7 @@ static ssize_t flashinfo_show(struct device *dev,
resp = (struct ec_response_flash_info *)msg->data; resp = (struct ec_response_flash_info *)msg->data;
ret = scnprintf(buf, PAGE_SIZE, ret = sysfs_emit(buf,
"FlashSize %d\nWriteSize %d\n" "FlashSize %d\nWriteSize %d\n"
"EraseSize %d\nProtectSize %d\n", "EraseSize %d\nProtectSize %d\n",
resp->flash_size, resp->write_block_size, resp->flash_size, resp->write_block_size,
...@@ -264,7 +264,7 @@ static ssize_t kb_wake_angle_show(struct device *dev, ...@@ -264,7 +264,7 @@ static ssize_t kb_wake_angle_show(struct device *dev,
goto exit; goto exit;
resp = (struct ec_response_motion_sense *)msg->data; resp = (struct ec_response_motion_sense *)msg->data;
ret = scnprintf(buf, PAGE_SIZE, "%d\n", resp->kb_wake_angle.ret); ret = sysfs_emit(buf, "%d\n", resp->kb_wake_angle.ret);
exit: exit:
kfree(msg); kfree(msg);
return ret; return ret;
......
...@@ -119,8 +119,7 @@ static ssize_t get_info(struct device *dev, char *buf, enum get_ec_info_op op) ...@@ -119,8 +119,7 @@ static ssize_t get_info(struct device *dev, char *buf, enum get_ec_info_op op)
if (ret < 0) if (ret < 0)
return ret; return ret;
return scnprintf(buf, PAGE_SIZE, "%.*s\n", (int)sizeof(resp.value), return sysfs_emit(buf, "%.*s\n", (int)sizeof(resp.value), (char *)&resp.value);
(char *)&resp.value);
} }
static ssize_t version_show(struct device *dev, struct device_attribute *attr, static ssize_t version_show(struct device *dev, struct device_attribute *attr,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment