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-sony.c:611:8-16: WARNING: use scnprintf or sprintf
drivers/hid/hid-sony.c:648:8-16: WARNING: use scnprintf or sprintf
drivers/hid/hid-sony.c:660: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-sony.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

--- a/drivers/hid/hid-sony.c
+++ b/drivers/hid/hid-sony.c
@@ -608,7 +608,7 @@ static ssize_t ds4_show_poll_interval(st
struct hid_device *hdev = to_hid_device(dev);
struct sony_sc *sc = hid_get_drvdata(hdev);

- return snprintf(buf, PAGE_SIZE, "%i\n", sc->ds4_bt_poll_interval);
+ return scnprintf(buf, PAGE_SIZE, "%i\n", sc->ds4_bt_poll_interval);
}

static ssize_t ds4_store_poll_interval(struct device *dev,
@@ -645,7 +645,7 @@ static ssize_t sony_show_firmware_versio
struct hid_device *hdev = to_hid_device(dev);
struct sony_sc *sc = hid_get_drvdata(hdev);

- return snprintf(buf, PAGE_SIZE, "0x%04x\n", sc->fw_version);
+ return scnprintf(buf, PAGE_SIZE, "0x%04x\n", sc->fw_version);
}

static DEVICE_ATTR(firmware_version, 0444, sony_show_firmware_version, NULL);
@@ -657,7 +657,7 @@ static ssize_t sony_show_hardware_versio
struct hid_device *hdev = to_hid_device(dev);
struct sony_sc *sc = hid_get_drvdata(hdev);

- return snprintf(buf, PAGE_SIZE, "0x%04x\n", sc->hw_version);
+ return scnprintf(buf, PAGE_SIZE, "0x%04x\n", sc->hw_version);
}

static DEVICE_ATTR(hardware_version, 0444, sony_show_hardware_version, NULL);
\
 
 \ /
  Last update: 2020-08-13 02:58    [W:1.097 / U:0.012 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site