Commit b251c0e7 authored by Tzung-Bi Shih's avatar Tzung-Bi Shih

platform/chrome: use sysfs_emit_at() 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 avatarTzung-Bi Shih <tzungbi@kernel.org>
Reviewed-by: default avatarGuenter Roeck <linux@roeck-us.net>
Link: https://lore.kernel.org/r/20221205061042.1774769-1-tzungbi@kernel.org
parent 256b734e
...@@ -27,10 +27,9 @@ static ssize_t reboot_show(struct device *dev, ...@@ -27,10 +27,9 @@ static ssize_t reboot_show(struct device *dev,
{ {
int count = 0; int count = 0;
count += scnprintf(buf + count, PAGE_SIZE - count, count += sysfs_emit_at(buf, count,
"ro|rw|cancel|cold|disable-jump|hibernate|cold-ap-off"); "ro|rw|cancel|cold|disable-jump|hibernate|cold-ap-off");
count += scnprintf(buf + count, PAGE_SIZE - count, count += sysfs_emit_at(buf, count, " [at-shutdown]\n");
" [at-shutdown]\n");
return count; return count;
} }
...@@ -138,12 +137,9 @@ static ssize_t version_show(struct device *dev, ...@@ -138,12 +137,9 @@ static ssize_t version_show(struct device *dev,
/* Strings should be null-terminated, but let's be sure. */ /* Strings should be null-terminated, but let's be sure. */
r_ver->version_string_ro[sizeof(r_ver->version_string_ro) - 1] = '\0'; r_ver->version_string_ro[sizeof(r_ver->version_string_ro) - 1] = '\0';
r_ver->version_string_rw[sizeof(r_ver->version_string_rw) - 1] = '\0'; r_ver->version_string_rw[sizeof(r_ver->version_string_rw) - 1] = '\0';
count += scnprintf(buf + count, PAGE_SIZE - count, count += sysfs_emit_at(buf, count, "RO version: %s\n", r_ver->version_string_ro);
"RO version: %s\n", r_ver->version_string_ro); count += sysfs_emit_at(buf, count, "RW version: %s\n", r_ver->version_string_rw);
count += scnprintf(buf + count, PAGE_SIZE - count, count += sysfs_emit_at(buf, count, "Firmware copy: %s\n",
"RW version: %s\n", r_ver->version_string_rw);
count += scnprintf(buf + count, PAGE_SIZE - count,
"Firmware copy: %s\n",
(r_ver->current_image < ARRAY_SIZE(image_names) ? (r_ver->current_image < ARRAY_SIZE(image_names) ?
image_names[r_ver->current_image] : "?")); image_names[r_ver->current_image] : "?"));
...@@ -152,13 +148,12 @@ static ssize_t version_show(struct device *dev, ...@@ -152,13 +148,12 @@ static ssize_t version_show(struct device *dev,
msg->insize = EC_HOST_PARAM_SIZE; msg->insize = EC_HOST_PARAM_SIZE;
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) {
count += scnprintf(buf + count, PAGE_SIZE - count, count += sysfs_emit_at(buf, count,
"Build info: XFER / EC ERROR %d / %d\n", "Build info: XFER / EC ERROR %d / %d\n",
ret, msg->result); ret, msg->result);
} else { } else {
msg->data[EC_HOST_PARAM_SIZE - 1] = '\0'; msg->data[EC_HOST_PARAM_SIZE - 1] = '\0';
count += scnprintf(buf + count, PAGE_SIZE - count, count += sysfs_emit_at(buf, count, "Build info: %s\n", msg->data);
"Build info: %s\n", msg->data);
} }
/* Get chip info. */ /* Get chip info. */
...@@ -166,7 +161,7 @@ static ssize_t version_show(struct device *dev, ...@@ -166,7 +161,7 @@ static ssize_t version_show(struct device *dev,
msg->insize = sizeof(*r_chip); msg->insize = sizeof(*r_chip);
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) {
count += scnprintf(buf + count, PAGE_SIZE - count, count += sysfs_emit_at(buf, count,
"Chip info: XFER / EC ERROR %d / %d\n", "Chip info: XFER / EC ERROR %d / %d\n",
ret, msg->result); ret, msg->result);
} else { } else {
...@@ -175,12 +170,9 @@ static ssize_t version_show(struct device *dev, ...@@ -175,12 +170,9 @@ static ssize_t version_show(struct device *dev,
r_chip->vendor[sizeof(r_chip->vendor) - 1] = '\0'; r_chip->vendor[sizeof(r_chip->vendor) - 1] = '\0';
r_chip->name[sizeof(r_chip->name) - 1] = '\0'; r_chip->name[sizeof(r_chip->name) - 1] = '\0';
r_chip->revision[sizeof(r_chip->revision) - 1] = '\0'; r_chip->revision[sizeof(r_chip->revision) - 1] = '\0';
count += scnprintf(buf + count, PAGE_SIZE - count, count += sysfs_emit_at(buf, count, "Chip vendor: %s\n", r_chip->vendor);
"Chip vendor: %s\n", r_chip->vendor); count += sysfs_emit_at(buf, count, "Chip name: %s\n", r_chip->name);
count += scnprintf(buf + count, PAGE_SIZE - count, count += sysfs_emit_at(buf, count, "Chip revision: %s\n", r_chip->revision);
"Chip name: %s\n", r_chip->name);
count += scnprintf(buf + count, PAGE_SIZE - count,
"Chip revision: %s\n", r_chip->revision);
} }
/* Get board version */ /* Get board version */
...@@ -188,13 +180,13 @@ static ssize_t version_show(struct device *dev, ...@@ -188,13 +180,13 @@ static ssize_t version_show(struct device *dev,
msg->insize = sizeof(*r_board); msg->insize = sizeof(*r_board);
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) {
count += scnprintf(buf + count, PAGE_SIZE - count, count += sysfs_emit_at(buf, count,
"Board version: XFER / EC ERROR %d / %d\n", "Board version: XFER / EC ERROR %d / %d\n",
ret, msg->result); ret, msg->result);
} else { } else {
r_board = (struct ec_response_board_version *)msg->data; r_board = (struct ec_response_board_version *)msg->data;
count += scnprintf(buf + count, PAGE_SIZE - count, count += sysfs_emit_at(buf, count,
"Board version: %d\n", "Board version: %d\n",
r_board->board_version); r_board->board_version);
} }
......
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