From mboxrd@z Thu Jan 1 00:00:00 1970 Content-Type: multipart/mixed; boundary="===============6815535136439729233==" MIME-Version: 1.0 From: kernel test robot Subject: [PATCH] coccinelle: api: fix device_attr_show.cocci warnings Date: Thu, 10 Sep 2020 16:53:26 +0800 Message-ID: <20200910085325.GA166674@27a6d1d494cf> In-Reply-To: <202009101641.j9NDzwl2%lkp@intel.com> List-Id: To: kbuild@lists.01.org --===============6815535136439729233== 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 Signed-off-by: kernel test robot --- tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git = master head: 7fe10096c1508c7f033d34d0741809f8eecc1ed4 commit: abfc19ff202d287742483e15fd478ddd6ada2187 coccinelle: api: add devic= e_attr_show script :::::: branch date: 6 hours ago :::::: commit date: 5 weeks 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, --===============6815535136439729233==--