* [PATCH] coccinelle: api: fix device_attr_show.cocci warnings
2020-06-25 4:50 [jlawall:for-5.9 1/3] drivers/base/core.c:1526:8-16: WARNING: use scnprintf or sprintf kernel test robot
@ 2020-06-25 4:50 ` kernel test robot
0 siblings, 0 replies; 2+ messages in thread
From: kernel test robot @ 2020-06-25 4:50 UTC (permalink / raw)
To: kbuild
[-- Attachment #1: Type: text/plain, Size: 2406 bytes --]
CC: kbuild-all(a)lists.01.org
TO: Denis Efremov <efremov@linux.com>
CC: Julia Lawall <Julia.Lawall@lip6.fr>
CC: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>
CC: "Rafael J. Wysocki" <rafael@kernel.org>
CC: linux-kernel(a)vger.kernel.org
From: kernel test robot <lkp@intel.com>
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 <efremov@linux.com>
Signed-off-by: kernel test robot <lkp@intel.com>
---
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);
^ permalink raw reply [flat|nested] 2+ messages in thread