From patchwork Tue Jan 16 04:51:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhijian Li \(Fujitsu\)" X-Patchwork-Id: 763246 Received: from esa3.hc1455-7.c3s2.iphmx.com (esa3.hc1455-7.c3s2.iphmx.com [207.54.90.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B7BE51E882; Tue, 16 Jan 2024 04:52:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=fujitsu.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fujitsu.com X-IronPort-AV: E=McAfee;i="6600,9927,10954"; a="146236512" X-IronPort-AV: E=Sophos;i="6.04,198,1695654000"; d="scan'208";a="146236512" Received: from unknown (HELO yto-r4.gw.nic.fujitsu.com) ([218.44.52.220]) by esa3.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jan 2024 13:52:29 +0900 Received: from yto-m4.gw.nic.fujitsu.com (yto-nat-yto-m4.gw.nic.fujitsu.com [192.168.83.67]) by yto-r4.gw.nic.fujitsu.com (Postfix) with ESMTP id 07564CD6C9; Tue, 16 Jan 2024 13:52:27 +0900 (JST) Received: from kws-ab3.gw.nic.fujitsu.com (kws-ab3.gw.nic.fujitsu.com [192.51.206.21]) by yto-m4.gw.nic.fujitsu.com (Postfix) with ESMTP id 3D19CD3F0C; Tue, 16 Jan 2024 13:52:26 +0900 (JST) Received: from edo.cn.fujitsu.com (edo.cn.fujitsu.com [10.167.33.5]) by kws-ab3.gw.nic.fujitsu.com (Postfix) with ESMTP id ADDC920098E39; Tue, 16 Jan 2024 13:52:25 +0900 (JST) Received: from localhost.localdomain (unknown [10.167.226.45]) by edo.cn.fujitsu.com (Postfix) with ESMTP id 6383C1A0070; Tue, 16 Jan 2024 12:52:25 +0800 (CST) From: Li Zhijian To: linux-kernel@vger.kernel.org Cc: Li Zhijian , "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org Subject: [PATCH 37/42] drivers/scsi/scsi_sysfs: Convert snprintf to sysfs_emit Date: Tue, 16 Jan 2024 12:51:46 +0800 Message-Id: <20240116045151.3940401-35-lizhijian@fujitsu.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240116045151.3940401-1-lizhijian@fujitsu.com> References: <20240116041129.3937800-1-lizhijian@fujitsu.com> <20240116045151.3940401-1-lizhijian@fujitsu.com> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-TM-AS-Product-Ver: IMSS-9.1.0.1417-9.0.0.1002-28122.004 X-TM-AS-User-Approved-Sender: Yes X-TMASE-Version: IMSS-9.1.0.1417-9.0.1002-28122.004 X-TMASE-Result: 10--15.188200-10.000000 X-TMASE-MatchedRID: e6WPXQD7Ri84ibokZ3+Q0CoiRKlBVkYIBXngI6jFvpfvd49YGReckE1N J2MN+nPkgxCMf8A0YpR5sRK06wHV4dL4Vi2vvkbTrMZ+BqQt2NrBOVz0Jwcxl6vCrG0TnfVUg9x e4gtUJtpqw4mhfH/CjyHVzwndHHhl/625ZdmTyUizRPQ8T4oe5Rgff28UuvITd3XtjqAaoMLndM EZZ6ppQ4E14EZ4ciLbm11lBSAav6kfE8yM4pjsDwtuKBGekqUpI/NGWt0UYPCv86Cgtufh8rUcX rQaDbBd7I2Y/HHWTXGIPKgr0MF740Ib4fU9zdME X-TMASE-SNAP-Result: 1.821001.0001-0-1-22:0,33:0,34:0-0 Per filesystems/sysfs.rst, show() should only use sysfs_emit() or sysfs_emit_at() when formatting the value to be returned to user space. coccinelle complains that there are still a couple of functions that use snprintf(). Convert them to sysfs_emit(). > ./drivers/scsi/scsi_sysfs.c:1112:9-17: WARNING: please use sysfs_emit > ./drivers/scsi/scsi_sysfs.c:1202:8-16: WARNING: please use sysfs_emit > ./drivers/scsi/scsi_sysfs.c:231:8-16: WARNING: please use sysfs_emit > ./drivers/scsi/scsi_sysfs.c:277:9-17: WARNING: please use sysfs_emit > ./drivers/scsi/scsi_sysfs.c:327:9-17: WARNING: please use sysfs_emit > ./drivers/scsi/scsi_sysfs.c:385:8-16: WARNING: please use sysfs_emit > ./drivers/scsi/scsi_sysfs.c:402:8-16: WARNING: please use sysfs_emit > ./drivers/scsi/scsi_sysfs.c:680:8-16: WARNING: please use sysfs_emit > ./drivers/scsi/scsi_sysfs.c:689:8-16: WARNING: please use sysfs_emit > ./drivers/scsi/scsi_sysfs.c:701:8-16: WARNING: please use sysfs_emit > ./drivers/scsi/scsi_sysfs.c:722:8-16: WARNING: please use sysfs_emit > ./drivers/scsi/scsi_sysfs.c:858:8-16: WARNING: please use sysfs_emit > ./drivers/scsi/scsi_sysfs.c:873:8-16: WARNING: please use sysfs_emit > ./drivers/scsi/scsi_sysfs.c:953:8-16: WARNING: please use sysfs_emit > ./drivers/scsi/scsi_sysfs.c:979:8-16: WARNING: please use sysfs_emit No functional change intended CC: "James E.J. Bottomley" CC: "Martin K. Petersen" CC: linux-scsi@vger.kernel.org Signed-off-by: Li Zhijian --- drivers/scsi/scsi_sysfs.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c index 24f6eefb6803..e82dc010fea0 100644 --- a/drivers/scsi/scsi_sysfs.c +++ b/drivers/scsi/scsi_sysfs.c @@ -228,7 +228,7 @@ show_shost_state(struct device *dev, struct device_attribute *attr, char *buf) if (!name) return -EINVAL; - return snprintf(buf, 20, "%s\n", name); + return sysfs_emit(buf, "%s\n", name); } /* DEVICE_ATTR(state) clashes with dev_attr_state for sdev */ @@ -274,7 +274,7 @@ show_shost_active_mode(struct device *dev, struct Scsi_Host *shost = class_to_shost(dev); if (shost->active_mode == MODE_UNKNOWN) - return snprintf(buf, 20, "unknown\n"); + return sysfs_emit(buf, "unknown\n"); else return show_shost_mode(shost->active_mode, buf); } @@ -324,7 +324,7 @@ show_shost_eh_deadline(struct device *dev, struct Scsi_Host *shost = class_to_shost(dev); if (shost->eh_deadline == -1) - return snprintf(buf, strlen("off") + 2, "off\n"); + return sysfs_emit(buf, "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 sysfs_emit(buf, "%d\n", scsi_host_busy(shost)); } static DEVICE_ATTR(host_busy, S_IRUGO, show_host_busy, NULL); @@ -399,7 +399,7 @@ show_nr_hw_queues(struct device *dev, struct device_attribute *attr, char *buf) struct Scsi_Host *shost = class_to_shost(dev); struct blk_mq_tag_set *tag_set = &shost->tag_set; - return snprintf(buf, 20, "%d\n", tag_set->nr_hw_queues); + return sysfs_emit(buf, "%d\n", tag_set->nr_hw_queues); } static DEVICE_ATTR(nr_hw_queues, S_IRUGO, show_nr_hw_queues, NULL); @@ -677,7 +677,7 @@ sdev_show_device_busy(struct device *dev, struct device_attribute *attr, char *buf) { struct scsi_device *sdev = to_scsi_device(dev); - return snprintf(buf, 20, "%d\n", scsi_device_busy(sdev)); + return sysfs_emit(buf, "%d\n", scsi_device_busy(sdev)); } static DEVICE_ATTR(device_busy, S_IRUGO, sdev_show_device_busy, NULL); @@ -686,7 +686,7 @@ sdev_show_device_blocked(struct device *dev, struct device_attribute *attr, char *buf) { struct scsi_device *sdev = to_scsi_device(dev); - return snprintf(buf, 20, "%d\n", atomic_read(&sdev->device_blocked)); + return sysfs_emit(buf, "%d\n", atomic_read(&sdev->device_blocked)); } static DEVICE_ATTR(device_blocked, S_IRUGO, sdev_show_device_blocked, NULL); @@ -698,7 +698,7 @@ sdev_show_timeout (struct device *dev, struct device_attribute *attr, char *buf) { struct scsi_device *sdev; sdev = to_scsi_device(dev); - return snprintf(buf, 20, "%d\n", sdev->request_queue->rq_timeout / HZ); + return sysfs_emit(buf, "%d\n", sdev->request_queue->rq_timeout / HZ); } static ssize_t @@ -719,7 +719,7 @@ sdev_show_eh_timeout(struct device *dev, struct device_attribute *attr, char *bu { struct scsi_device *sdev; sdev = to_scsi_device(dev); - return snprintf(buf, 20, "%u\n", sdev->eh_timeout / HZ); + return sysfs_emit(buf, "%u\n", sdev->eh_timeout / HZ); } static ssize_t @@ -855,7 +855,7 @@ show_state_field(struct device *dev, struct device_attribute *attr, char *buf) if (!name) return -EINVAL; - return snprintf(buf, 20, "%s\n", name); + return sysfs_emit(buf, "%s\n", name); } static DEVICE_ATTR(state, S_IRUGO | S_IWUSR, show_state_field, store_state_field); @@ -870,7 +870,7 @@ show_queue_type_field(struct device *dev, struct device_attribute *attr, if (sdev->simple_tags) name = "simple"; - return snprintf(buf, 20, "%s\n", name); + return sysfs_emit(buf, "%s\n", name); } static ssize_t @@ -950,7 +950,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 sysfs_emit(buf, "%d\n", (int)sizeof(atomic_t) * 8); } static DEVICE_ATTR(iocounterbits, S_IRUGO, show_iostat_counterbits, NULL); @@ -976,7 +976,7 @@ sdev_show_modalias(struct device *dev, struct device_attribute *attr, char *buf) { struct scsi_device *sdev; sdev = to_scsi_device(dev); - return snprintf (buf, 20, SCSI_DEVICE_MODALIAS_FMT "\n", sdev->type); + return sysfs_emit(buf, SCSI_DEVICE_MODALIAS_FMT "\n", sdev->type); } static DEVICE_ATTR(modalias, S_IRUGO, sdev_show_modalias, NULL); @@ -1109,9 +1109,9 @@ sdev_show_dh_state(struct device *dev, struct device_attribute *attr, struct scsi_device *sdev = to_scsi_device(dev); if (!sdev->handler) - return snprintf(buf, 20, "detached\n"); + return sysfs_emit(buf, "detached\n"); - return snprintf(buf, 20, "%s\n", sdev->handler->name); + return sysfs_emit(buf, "%s\n", sdev->handler->name); } static ssize_t @@ -1199,8 +1199,8 @@ sdev_show_queue_ramp_up_period(struct device *dev, { struct scsi_device *sdev; sdev = to_scsi_device(dev); - return snprintf(buf, 20, "%u\n", - jiffies_to_msecs(sdev->queue_ramp_up_period)); + return sysfs_emit(buf, "%u\n", + jiffies_to_msecs(sdev->queue_ramp_up_period)); } static ssize_t