Skip to content

Commit 247481b

Browse files
zhijianli88Jiri Kosina
authored andcommitted
HID: hid-picolcd*: Convert sprintf() family to sysfs_emit() family
Per filesystems/sysfs.rst, show() should only use sysfs_emit() or sysfs_emit_at() when formatting the value to be returned to user space. coccinelle complains that there are still a couple of functions that use snprintf(). Convert them to sysfs_emit(). sprintf() and scnprintf() will be converted as well if they have. Generally, this patch is generated by make coccicheck M=<path/to/file> MODE=patch \ COCCI=scripts/coccinelle/api/device_attr_show.cocci No functional change intended CC: Christophe JAILLET <[email protected]> CC: "Bruno Prémont" <[email protected]> CC: Jiri Kosina <[email protected]> CC: Benjamin Tissoires <[email protected]> CC: [email protected] Signed-off-by: Li Zhijian <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 3e78a6c commit 247481b

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

drivers/hid/hid-picolcd_core.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,9 @@ static ssize_t picolcd_operation_mode_show(struct device *dev,
256256
struct picolcd_data *data = dev_get_drvdata(dev);
257257

258258
if (data->status & PICOLCD_BOOTLOADER)
259-
return snprintf(buf, PAGE_SIZE, "[bootloader] lcd\n");
259+
return sysfs_emit(buf, "[bootloader] lcd\n");
260260
else
261-
return snprintf(buf, PAGE_SIZE, "bootloader [lcd]\n");
261+
return sysfs_emit(buf, "bootloader [lcd]\n");
262262
}
263263

264264
static ssize_t picolcd_operation_mode_store(struct device *dev,
@@ -301,7 +301,7 @@ static ssize_t picolcd_operation_mode_delay_show(struct device *dev,
301301
{
302302
struct picolcd_data *data = dev_get_drvdata(dev);
303303

304-
return snprintf(buf, PAGE_SIZE, "%hu\n", data->opmode_delay);
304+
return sysfs_emit(buf, "%hu\n", data->opmode_delay);
305305
}
306306

307307
static ssize_t picolcd_operation_mode_delay_store(struct device *dev,

drivers/hid/hid-picolcd_fb.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -421,12 +421,10 @@ static ssize_t picolcd_fb_update_rate_show(struct device *dev,
421421
size_t ret = 0;
422422

423423
for (i = 1; i <= PICOLCDFB_UPDATE_RATE_LIMIT; i++)
424-
if (ret >= PAGE_SIZE)
425-
break;
426-
else if (i == fb_update_rate)
427-
ret += scnprintf(buf+ret, PAGE_SIZE-ret, "[%u] ", i);
424+
if (i == fb_update_rate)
425+
ret += sysfs_emit_at(buf, ret, "[%u] ", i);
428426
else
429-
ret += scnprintf(buf+ret, PAGE_SIZE-ret, "%u ", i);
427+
ret += sysfs_emit_at(buf, ret, "%u ", i);
430428
if (ret > 0)
431429
buf[min(ret, (size_t)PAGE_SIZE)-1] = '\n';
432430
return ret;

0 commit comments

Comments
 (0)