CC: kbuild-all(a)lists.01.org TO: Denis Efremov CC: Julia Lawall CC: "Greg Kroah-Hartman" CC: "Rafael J. Wysocki" CC: linux-kernel(a)vger.kernel.org From: kernel test robot drivers/base/core.c:1526:8-16: WARNING: use scnprintf or sprintf drivers/base/core.c:1505:8-16: WARNING: use scnprintf or sprintf drivers/base/core.c:1475:8-16: WARNING: use scnprintf or sprintf From Documentation/filesystems/sysfs.txt: show() must not use snprintf() when formatting the value to be returned to user space. If you can guarantee that an overflow will never happen you can use sprintf() otherwise you must use scnprintf(). Generated by: scripts/coccinelle/api/device_attr_show.cocci Fixes: 988676da8375 ("coccinelle: api: add device_attr_show script") CC: Denis Efremov Signed-off-by: kernel test robot --- tree: https://git.kernel.org/pub/scm/linux/kernel/git/jlawall/linux.git for-5.9 head: 9bba51dafe9fe6bdaa0ef557ea322e981e85bf4c commit: 988676da837516bbfafda5478472fd4265f0de4e [1/3] coccinelle: api: add device_attr_show script :::::: branch date: 9 hours ago :::::: commit date: 9 hours ago Please take the patch only if it's a positive warning. Thanks! core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -1472,7 +1472,7 @@ ssize_t device_show_ulong(struct device char *buf) { struct dev_ext_attribute *ea = to_ext_attr(attr); - return snprintf(buf, PAGE_SIZE, "%lx\n", *(unsigned long *)(ea->var)); + return scnprintf(buf, PAGE_SIZE, "%lx\n", *(unsigned long *)(ea->var)); } EXPORT_SYMBOL_GPL(device_show_ulong); @@ -1502,7 +1502,7 @@ ssize_t device_show_int(struct device *d { struct dev_ext_attribute *ea = to_ext_attr(attr); - return snprintf(buf, PAGE_SIZE, "%d\n", *(int *)(ea->var)); + return scnprintf(buf, PAGE_SIZE, "%d\n", *(int *)(ea->var)); } EXPORT_SYMBOL_GPL(device_show_int); @@ -1523,7 +1523,7 @@ ssize_t device_show_bool(struct device * { struct dev_ext_attribute *ea = to_ext_attr(attr); - return snprintf(buf, PAGE_SIZE, "%d\n", *(bool *)(ea->var)); + return scnprintf(buf, PAGE_SIZE, "%d\n", *(bool *)(ea->var)); } EXPORT_SYMBOL_GPL(device_show_bool);