From mboxrd@z Thu Jan 1 00:00:00 1970 Content-Type: multipart/mixed; boundary="===============0372376850164645877==" MIME-Version: 1.0 From: kernel test robot Subject: [PATCH] coccinelle: api: fix device_attr_show.cocci warnings Date: Thu, 27 Aug 2020 03:38:11 +0800 Message-ID: <20200826193810.GA13253@d10202f75172> In-Reply-To: <202008270349.cJngRMCK%lkp@intel.com> List-Id: To: kbuild@lists.01.org --===============0372376850164645877== 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: Adaptec OEM Raid Solutions CC: "James E.J. Bottomley" CC: "Martin K. Petersen" CC: linux-scsi(a)vger.kernel.org CC: linux-kernel(a)vger.kernel.org From: kernel test robot drivers/scsi/aacraid/linit.c:1355:8-16: WARNING: use scnprintf or sprintf drivers/scsi/aacraid/linit.c:1381:8-16: WARNING: use scnprintf or sprintf drivers/scsi/aacraid/linit.c:1388:8-16: WARNING: use scnprintf or sprintf drivers/scsi/aacraid/linit.c:563:9-17: WARNING: use scnprintf or sprintf drivers/scsi/aacraid/linit.c:590: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: 2ac69819ba9e3d8d550bb5d2d2df74848e556812 commit: abfc19ff202d287742483e15fd478ddd6ada2187 coccinelle: api: add devic= e_attr_show script :::::: branch date: 19 hours ago :::::: commit date: 3 weeks ago Please take the patch only if it's a positive warning. Thanks! linit.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) --- a/drivers/scsi/aacraid/linit.c +++ b/drivers/scsi/aacraid/linit.c @@ -560,10 +560,10 @@ static ssize_t aac_show_raid_level(struc struct scsi_device *sdev =3D to_scsi_device(dev); struct aac_dev *aac =3D (struct aac_dev *)(sdev->host->hostdata); if (sdev_channel(sdev) !=3D CONTAINER_CHANNEL) - return snprintf(buf, PAGE_SIZE, sdev->no_uld_attach + return scnprintf(buf, PAGE_SIZE, sdev->no_uld_attach ? "Hidden\n" : ((aac->jbod && (sdev->type =3D=3D TYPE_DISK)) ? "JBOD\n" : "")); - return snprintf(buf, PAGE_SIZE, "%s\n", + return scnprintf(buf, PAGE_SIZE, "%s\n", get_container_type(aac->fsa_dev[sdev_id(sdev)].type)); } = @@ -587,7 +587,7 @@ static ssize_t aac_show_unique_id(struct if (sdev_channel(sdev) =3D=3D CONTAINER_CHANNEL) memcpy(sn, aac->fsa_dev[sdev_id(sdev)].identifier, sizeof(sn)); = - return snprintf(buf, 16 * 2 + 2, + return scnprintf(buf, 16 * 2 + 2, "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X\n", sn[0], sn[1], sn[2], sn[3], sn[4], sn[5], sn[6], sn[7], @@ -1352,7 +1352,7 @@ static ssize_t aac_show_driver_version(s struct device_attribute *attr, char *buf) { - return snprintf(buf, PAGE_SIZE, "%s\n", aac_driver_version); + return scnprintf(buf, PAGE_SIZE, "%s\n", aac_driver_version); } = static ssize_t aac_show_serial_number(struct device *device, @@ -1378,14 +1378,14 @@ static ssize_t aac_show_serial_number(st static ssize_t aac_show_max_channel(struct device *device, struct device_attribute *attr, char *buf) { - return snprintf(buf, PAGE_SIZE, "%d\n", + return scnprintf(buf, PAGE_SIZE, "%d\n", class_to_shost(device)->max_channel); } = static ssize_t aac_show_max_id(struct device *device, struct device_attribute *attr, char *buf) { - return snprintf(buf, PAGE_SIZE, "%d\n", + return scnprintf(buf, PAGE_SIZE, "%d\n", class_to_shost(device)->max_id); } =20 --===============0372376850164645877==--