From mboxrd@z Thu Jan 1 00:00:00 1970 Content-Type: multipart/mixed; boundary="===============9037936678904874768==" MIME-Version: 1.0 From: kernel test robot Subject: [PATCH] coccinelle: api: fix device_attr_show.cocci warnings Date: Sun, 22 Nov 2020 18:27:44 +0800 Message-ID: <20201122102744.GA83470@5bd5fb583047> In-Reply-To: <202011221838.CuWVFvxS-lkp@intel.com> List-Id: To: kbuild@lists.01.org --===============9037936678904874768== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable CC: kbuild-all(a)lists.01.org CC: linux-kernel(a)vger.kernel.org TO: Denis Efremov CC: Julia Lawall CC: Jean Delvare CC: Guenter Roeck CC: linux-hwmon(a)vger.kernel.org CC: linux-kernel(a)vger.kernel.org From: kernel test robot drivers/hwmon/occ/sysfs.c:80:8-16: WARNING: use scnprintf or sprintf drivers/hwmon/occ/sysfs.c:70: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 Reported-by: kernel test robot Signed-off-by: kernel test robot --- tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git = master head: a349e4c659609fd20e4beea89e5c4a4038e33a95 commit: abfc19ff202d287742483e15fd478ddd6ada2187 coccinelle: api: add devic= e_attr_show script :::::: branch date: 16 hours ago :::::: commit date: 4 months ago Please take the patch only if it's a positive warning. Thanks! sysfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/drivers/hwmon/occ/sysfs.c +++ b/drivers/hwmon/occ/sysfs.c @@ -67,7 +67,7 @@ static ssize_t occ_sysfs_show(struct dev return -EINVAL; } = - return snprintf(buf, PAGE_SIZE - 1, "%d\n", val); + return scnprintf(buf, PAGE_SIZE - 1, "%d\n", val); } = static ssize_t occ_error_show(struct device *dev, @@ -77,7 +77,7 @@ static ssize_t occ_error_show(struct dev = occ_update_response(occ); = - return snprintf(buf, PAGE_SIZE - 1, "%d\n", occ->error); + return scnprintf(buf, PAGE_SIZE - 1, "%d\n", occ->error); } = static SENSOR_DEVICE_ATTR(occ_master, 0444, occ_sysfs_show, NULL, 0); --===============9037936678904874768==--