lkml.org 
[lkml]   [2020]   [Aug]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH] coccinelle: api: fix device_attr_show.cocci warnings
From: kernel test robot <lkp@intel.com>

drivers/hid/hid-roccat-pyra.c:289:8-16: WARNING: use scnprintf or sprintf
drivers/hid/hid-roccat-pyra.c:306:8-16: WARNING: use scnprintf or sprintf
drivers/hid/hid-roccat-pyra.c:327: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: abfc19ff202d ("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/torvalds/linux.git master
head: 7c2a69f610e64c8dec6a06a66e721f4ce1dd783a
commit: abfc19ff202d287742483e15fd478ddd6ada2187 coccinelle: api: add device_attr_show script

Please take the patch only if it's a positive warning. Thanks!

hid-roccat-pyra.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

--- a/drivers/hid/hid-roccat-pyra.c
+++ b/drivers/hid/hid-roccat-pyra.c
@@ -286,7 +286,7 @@ static ssize_t pyra_sysfs_show_actual_cp
{
struct pyra_device *pyra =
hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
- return snprintf(buf, PAGE_SIZE, "%d\n", pyra->actual_cpi);
+ return scnprintf(buf, PAGE_SIZE, "%d\n", pyra->actual_cpi);
}
static DEVICE_ATTR(actual_cpi, 0440, pyra_sysfs_show_actual_cpi, NULL);

@@ -303,7 +303,7 @@ static ssize_t pyra_sysfs_show_actual_pr
&settings, PYRA_SIZE_SETTINGS);
mutex_unlock(&pyra->pyra_lock);

- return snprintf(buf, PAGE_SIZE, "%d\n", settings.startup_profile);
+ return scnprintf(buf, PAGE_SIZE, "%d\n", settings.startup_profile);
}
static DEVICE_ATTR(actual_profile, 0440, pyra_sysfs_show_actual_profile, NULL);
static DEVICE_ATTR(startup_profile, 0440, pyra_sysfs_show_actual_profile, NULL);
@@ -324,7 +324,7 @@ static ssize_t pyra_sysfs_show_firmware_
&info, PYRA_SIZE_INFO);
mutex_unlock(&pyra->pyra_lock);

- return snprintf(buf, PAGE_SIZE, "%d\n", info.firmware_version);
+ return scnprintf(buf, PAGE_SIZE, "%d\n", info.firmware_version);
}
static DEVICE_ATTR(firmware_version, 0440, pyra_sysfs_show_firmware_version,
NULL);
\
 
 \ /
  Last update: 2020-08-13 02:58    [W:0.051 / U:1.456 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site