Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <christophe.jaillet@wanadoo.fr>
CC: "Bruno Prémont" <bonbons@linux-vserver.org>
CC: Jiri Kosina <jikos@kernel.org>
CC: Benjamin Tissoires <benjamin.tissoires@redhat.com>
CC: linux-input@vger.kernel.org
Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
Signed-off-by: Jiri Kosina <jkosina@suse.com>

authored by

Li Zhijian and committed by
Jiri Kosina
247481b8 3e78a6c0

+6 -8
+3 -3
drivers/hid/hid-picolcd_core.c
··· 256 256 struct picolcd_data *data = dev_get_drvdata(dev); 257 257 258 258 if (data->status & PICOLCD_BOOTLOADER) 259 - return snprintf(buf, PAGE_SIZE, "[bootloader] lcd\n"); 259 + return sysfs_emit(buf, "[bootloader] lcd\n"); 260 260 else 261 - return snprintf(buf, PAGE_SIZE, "bootloader [lcd]\n"); 261 + return sysfs_emit(buf, "bootloader [lcd]\n"); 262 262 } 263 263 264 264 static ssize_t picolcd_operation_mode_store(struct device *dev, ··· 301 301 { 302 302 struct picolcd_data *data = dev_get_drvdata(dev); 303 303 304 - return snprintf(buf, PAGE_SIZE, "%hu\n", data->opmode_delay); 304 + return sysfs_emit(buf, "%hu\n", data->opmode_delay); 305 305 } 306 306 307 307 static ssize_t picolcd_operation_mode_delay_store(struct device *dev,
+3 -5
drivers/hid/hid-picolcd_fb.c
··· 421 421 size_t ret = 0; 422 422 423 423 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); 428 426 else 429 - ret += scnprintf(buf+ret, PAGE_SIZE-ret, "%u ", i); 427 + ret += sysfs_emit_at(buf, ret, "%u ", i); 430 428 if (ret > 0) 431 429 buf[min(ret, (size_t)PAGE_SIZE)-1] = '\n'; 432 430 return ret;