From mboxrd@z Thu Jan 1 00:00:00 1970 Content-Type: multipart/mixed; boundary="===============1555833165545597500==" MIME-Version: 1.0 From: kernel test robot Subject: [PATCH] coccinelle: api: fix device_attr_show.cocci warnings Date: Sat, 14 Nov 2020 01:02:04 +0800 Message-ID: <20201113170204.GA73049@690bb2050ccd> In-Reply-To: <202011140028.IqpmXoZz-lkp@intel.com> List-Id: To: kbuild@lists.01.org --===============1555833165545597500== 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: Harald Welte CC: Darren Hart CC: Andy Shevchenko CC: platform-driver-x86(a)vger.kernel.org CC: linux-kernel(a)vger.kernel.org From: kernel test robot drivers/platform/x86/panasonic-laptop.c:371:8-16: WARNING: use scnprintf or= sprintf drivers/platform/x86/panasonic-laptop.c:383:8-16: WARNING: use scnprintf or= sprintf drivers/platform/x86/panasonic-laptop.c:359:8-16: WARNING: use scnprintf or= sprintf drivers/platform/x86/panasonic-laptop.c:395: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: 585e5b17b92dead8a3aca4e3c9876fbca5f7e0ba commit: abfc19ff202d287742483e15fd478ddd6ada2187 coccinelle: api: add devic= e_attr_show script :::::: branch date: 16 hours ago :::::: commit date: 3 months ago Please take the patch only if it's a positive warning. Thanks! panasonic-laptop.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) --- a/drivers/platform/x86/panasonic-laptop.c +++ b/drivers/platform/x86/panasonic-laptop.c @@ -356,7 +356,7 @@ static ssize_t show_numbatt(struct devic if (!acpi_pcc_retrieve_biosdata(pcc)) return -EIO; = - return snprintf(buf, PAGE_SIZE, "%u\n", pcc->sinf[SINF_NUM_BATTERIES]); + return scnprintf(buf, PAGE_SIZE, "%u\n", pcc->sinf[SINF_NUM_BATTERIES]); } = static ssize_t show_lcdtype(struct device *dev, struct device_attribute *a= ttr, @@ -368,7 +368,7 @@ static ssize_t show_lcdtype(struct devic if (!acpi_pcc_retrieve_biosdata(pcc)) return -EIO; = - return snprintf(buf, PAGE_SIZE, "%u\n", pcc->sinf[SINF_LCD_TYPE]); + return scnprintf(buf, PAGE_SIZE, "%u\n", pcc->sinf[SINF_LCD_TYPE]); } = static ssize_t show_mute(struct device *dev, struct device_attribute *attr, @@ -380,7 +380,7 @@ static ssize_t show_mute(struct device * if (!acpi_pcc_retrieve_biosdata(pcc)) return -EIO; = - return snprintf(buf, PAGE_SIZE, "%u\n", pcc->sinf[SINF_MUTE]); + return scnprintf(buf, PAGE_SIZE, "%u\n", pcc->sinf[SINF_MUTE]); } = static ssize_t show_sticky(struct device *dev, struct device_attribute *at= tr, @@ -392,7 +392,7 @@ static ssize_t show_sticky(struct device if (!acpi_pcc_retrieve_biosdata(pcc)) return -EIO; = - return snprintf(buf, PAGE_SIZE, "%u\n", pcc->sinf[SINF_STICKY_KEY]); + return scnprintf(buf, PAGE_SIZE, "%u\n", pcc->sinf[SINF_STICKY_KEY]); } = static ssize_t set_sticky(struct device *dev, struct device_attribute *att= r, --===============1555833165545597500==--