CC: kbuild-all(a)lists.01.org TO: Denis Efremov CC: Julia Lawall 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/scsi_sysfs.c:671:8-16: WARNING: use scnprintf or sprintf drivers/scsi/scsi_sysfs.c:662:8-16: WARNING: use scnprintf or sprintf drivers/scsi/scsi_sysfs.c:1068:9-17: WARNING: use scnprintf or sprintf drivers/scsi/scsi_sysfs.c:704:8-16: WARNING: use scnprintf or sprintf drivers/scsi/scsi_sysfs.c:935:8-16: WARNING: use scnprintf or sprintf drivers/scsi/scsi_sysfs.c:1158:8-16: WARNING: use scnprintf or sprintf drivers/scsi/scsi_sysfs.c:683:8-16: WARNING: use scnprintf or sprintf drivers/scsi/scsi_sysfs.c:385:8-16: WARNING: use scnprintf or sprintf drivers/scsi/scsi_sysfs.c:910:8-16: WARNING: use scnprintf or sprintf drivers/scsi/scsi_sysfs.c:833:8-16: WARNING: use scnprintf or sprintf drivers/scsi/scsi_sysfs.c:276:9-17: WARNING: use scnprintf or sprintf drivers/scsi/scsi_sysfs.c:326:9-17: WARNING: use scnprintf or sprintf drivers/scsi/scsi_sysfs.c:230:8-16: WARNING: use scnprintf or sprintf drivers/scsi/scsi_sysfs.c:818: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: 988676da8375 ("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/jlawall/linux.git for-5.9 head: 5502a4eb3af819792a6c43b418c401f613a39d02 commit: 988676da837516bbfafda5478472fd4265f0de4e [1/3] coccinelle: api: add device_attr_show script :::::: branch date: 8 days ago :::::: commit date: 9 days ago Please take the patch only if it's a positive warning. Thanks! scsi_sysfs.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) --- a/drivers/scsi/scsi_sysfs.c +++ b/drivers/scsi/scsi_sysfs.c @@ -227,7 +227,7 @@ show_shost_state(struct device *dev, str if (!name) return -EINVAL; - return snprintf(buf, 20, "%s\n", name); + return scnprintf(buf, 20, "%s\n", name); } /* DEVICE_ATTR(state) clashes with dev_attr_state for sdev */ @@ -273,7 +273,7 @@ show_shost_active_mode(struct device *de struct Scsi_Host *shost = class_to_shost(dev); if (shost->active_mode == MODE_UNKNOWN) - return snprintf(buf, 20, "unknown\n"); + return scnprintf(buf, 20, "unknown\n"); else return show_shost_mode(shost->active_mode, buf); } @@ -323,7 +323,7 @@ show_shost_eh_deadline(struct device *de struct Scsi_Host *shost = class_to_shost(dev); if (shost->eh_deadline == -1) - return snprintf(buf, strlen("off") + 2, "off\n"); + return scnprintf(buf, strlen("off") + 2, "off\n"); return sprintf(buf, "%u\n", shost->eh_deadline / HZ); } @@ -382,7 +382,7 @@ static ssize_t show_host_busy(struct device *dev, struct device_attribute *attr, char *buf) { struct Scsi_Host *shost = class_to_shost(dev); - return snprintf(buf, 20, "%d\n", scsi_host_busy(shost)); + return scnprintf(buf, 20, "%d\n", scsi_host_busy(shost)); } static DEVICE_ATTR(host_busy, S_IRUGO, show_host_busy, NULL); @@ -659,7 +659,7 @@ sdev_show_device_busy(struct device *dev char *buf) { struct scsi_device *sdev = to_scsi_device(dev); - return snprintf(buf, 20, "%d\n", atomic_read(&sdev->device_busy)); + return scnprintf(buf, 20, "%d\n", atomic_read(&sdev->device_busy)); } static DEVICE_ATTR(device_busy, S_IRUGO, sdev_show_device_busy, NULL); @@ -668,7 +668,7 @@ sdev_show_device_blocked(struct device * char *buf) { struct scsi_device *sdev = to_scsi_device(dev); - return snprintf(buf, 20, "%d\n", atomic_read(&sdev->device_blocked)); + return scnprintf(buf, 20, "%d\n", atomic_read(&sdev->device_blocked)); } static DEVICE_ATTR(device_blocked, S_IRUGO, sdev_show_device_blocked, NULL); @@ -680,7 +680,7 @@ sdev_show_timeout (struct device *dev, s { struct scsi_device *sdev; sdev = to_scsi_device(dev); - return snprintf(buf, 20, "%d\n", sdev->request_queue->rq_timeout / HZ); + return scnprintf(buf, 20, "%d\n", sdev->request_queue->rq_timeout / HZ); } static ssize_t @@ -701,7 +701,7 @@ sdev_show_eh_timeout(struct device *dev, { struct scsi_device *sdev; sdev = to_scsi_device(dev); - return snprintf(buf, 20, "%u\n", sdev->eh_timeout / HZ); + return scnprintf(buf, 20, "%u\n", sdev->eh_timeout / HZ); } static ssize_t @@ -815,7 +815,7 @@ show_state_field(struct device *dev, str if (!name) return -EINVAL; - return snprintf(buf, 20, "%s\n", name); + return scnprintf(buf, 20, "%s\n", name); } static DEVICE_ATTR(state, S_IRUGO | S_IWUSR, show_state_field, store_state_field); @@ -830,7 +830,7 @@ show_queue_type_field(struct device *dev if (sdev->simple_tags) name = "simple"; - return snprintf(buf, 20, "%s\n", name); + return scnprintf(buf, 20, "%s\n", name); } static ssize_t @@ -907,7 +907,7 @@ static ssize_t show_iostat_counterbits(struct device *dev, struct device_attribute *attr, char *buf) { - return snprintf(buf, 20, "%d\n", (int)sizeof(atomic_t) * 8); + return scnprintf(buf, 20, "%d\n", (int)sizeof(atomic_t) * 8); } static DEVICE_ATTR(iocounterbits, S_IRUGO, show_iostat_counterbits, NULL); @@ -932,7 +932,7 @@ sdev_show_modalias(struct device *dev, s { struct scsi_device *sdev; sdev = to_scsi_device(dev); - return snprintf (buf, 20, SCSI_DEVICE_MODALIAS_FMT "\n", sdev->type); + return scnprintf (buf, 20, SCSI_DEVICE_MODALIAS_FMT "\n", sdev->type); } static DEVICE_ATTR(modalias, S_IRUGO, sdev_show_modalias, NULL); @@ -1065,9 +1065,9 @@ sdev_show_dh_state(struct device *dev, s struct scsi_device *sdev = to_scsi_device(dev); if (!sdev->handler) - return snprintf(buf, 20, "detached\n"); + return scnprintf(buf, 20, "detached\n"); - return snprintf(buf, 20, "%s\n", sdev->handler->name); + return scnprintf(buf, 20, "%s\n", sdev->handler->name); } static ssize_t @@ -1155,7 +1155,7 @@ sdev_show_queue_ramp_up_period(struct de { struct scsi_device *sdev; sdev = to_scsi_device(dev); - return snprintf(buf, 20, "%u\n", + return scnprintf(buf, 20, "%u\n", jiffies_to_msecs(sdev->queue_ramp_up_period)); }