Skip to content

Commit b251c0e

Browse files
author
Tzung-Bi Shih
committed
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: Tzung-Bi Shih <tzungbi@kernel.org> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Link: https://lore.kernel.org/r/20221205061042.1774769-1-tzungbi@kernel.org
1 parent 256b734 commit b251c0e

File tree

1 file changed

+14
-22
lines changed

1 file changed

+14
-22
lines changed

drivers/platform/chrome/cros_ec_sysfs.c

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ static ssize_t reboot_show(struct device *dev,
2727
{
2828
int count = 0;
2929

30-
count += scnprintf(buf + count, PAGE_SIZE - count,
31-
"ro|rw|cancel|cold|disable-jump|hibernate|cold-ap-off");
32-
count += scnprintf(buf + count, PAGE_SIZE - count,
33-
" [at-shutdown]\n");
30+
count += sysfs_emit_at(buf, count,
31+
"ro|rw|cancel|cold|disable-jump|hibernate|cold-ap-off");
32+
count += sysfs_emit_at(buf, count, " [at-shutdown]\n");
3433
return count;
3534
}
3635

@@ -138,12 +137,9 @@ static ssize_t version_show(struct device *dev,
138137
/* Strings should be null-terminated, but let's be sure. */
139138
r_ver->version_string_ro[sizeof(r_ver->version_string_ro) - 1] = '\0';
140139
r_ver->version_string_rw[sizeof(r_ver->version_string_rw) - 1] = '\0';
141-
count += scnprintf(buf + count, PAGE_SIZE - count,
142-
"RO version: %s\n", r_ver->version_string_ro);
143-
count += scnprintf(buf + count, PAGE_SIZE - count,
144-
"RW version: %s\n", r_ver->version_string_rw);
145-
count += scnprintf(buf + count, PAGE_SIZE - count,
146-
"Firmware copy: %s\n",
140+
count += sysfs_emit_at(buf, count, "RO version: %s\n", r_ver->version_string_ro);
141+
count += sysfs_emit_at(buf, count, "RW version: %s\n", r_ver->version_string_rw);
142+
count += sysfs_emit_at(buf, count, "Firmware copy: %s\n",
147143
(r_ver->current_image < ARRAY_SIZE(image_names) ?
148144
image_names[r_ver->current_image] : "?"));
149145

@@ -152,21 +148,20 @@ static ssize_t version_show(struct device *dev,
152148
msg->insize = EC_HOST_PARAM_SIZE;
153149
ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
154150
if (ret < 0) {
155-
count += scnprintf(buf + count, PAGE_SIZE - count,
151+
count += sysfs_emit_at(buf, count,
156152
"Build info: XFER / EC ERROR %d / %d\n",
157153
ret, msg->result);
158154
} else {
159155
msg->data[EC_HOST_PARAM_SIZE - 1] = '\0';
160-
count += scnprintf(buf + count, PAGE_SIZE - count,
161-
"Build info: %s\n", msg->data);
156+
count += sysfs_emit_at(buf, count, "Build info: %s\n", msg->data);
162157
}
163158

164159
/* Get chip info. */
165160
msg->command = EC_CMD_GET_CHIP_INFO + ec->cmd_offset;
166161
msg->insize = sizeof(*r_chip);
167162
ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
168163
if (ret < 0) {
169-
count += scnprintf(buf + count, PAGE_SIZE - count,
164+
count += sysfs_emit_at(buf, count,
170165
"Chip info: XFER / EC ERROR %d / %d\n",
171166
ret, msg->result);
172167
} else {
@@ -175,26 +170,23 @@ static ssize_t version_show(struct device *dev,
175170
r_chip->vendor[sizeof(r_chip->vendor) - 1] = '\0';
176171
r_chip->name[sizeof(r_chip->name) - 1] = '\0';
177172
r_chip->revision[sizeof(r_chip->revision) - 1] = '\0';
178-
count += scnprintf(buf + count, PAGE_SIZE - count,
179-
"Chip vendor: %s\n", r_chip->vendor);
180-
count += scnprintf(buf + count, PAGE_SIZE - count,
181-
"Chip name: %s\n", r_chip->name);
182-
count += scnprintf(buf + count, PAGE_SIZE - count,
183-
"Chip revision: %s\n", r_chip->revision);
173+
count += sysfs_emit_at(buf, count, "Chip vendor: %s\n", r_chip->vendor);
174+
count += sysfs_emit_at(buf, count, "Chip name: %s\n", r_chip->name);
175+
count += sysfs_emit_at(buf, count, "Chip revision: %s\n", r_chip->revision);
184176
}
185177

186178
/* Get board version */
187179
msg->command = EC_CMD_GET_BOARD_VERSION + ec->cmd_offset;
188180
msg->insize = sizeof(*r_board);
189181
ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
190182
if (ret < 0) {
191-
count += scnprintf(buf + count, PAGE_SIZE - count,
183+
count += sysfs_emit_at(buf, count,
192184
"Board version: XFER / EC ERROR %d / %d\n",
193185
ret, msg->result);
194186
} else {
195187
r_board = (struct ec_response_board_version *)msg->data;
196188

197-
count += scnprintf(buf + count, PAGE_SIZE - count,
189+
count += sysfs_emit_at(buf, count,
198190
"Board version: %d\n",
199191
r_board->board_version);
200192
}

0 commit comments

Comments
 (0)