diff mbox series

[22/42] drivers/scsi/fnic: Convert snprintf to sysfs_emit

Message ID 20240116045151.3940401-20-lizhijian@fujitsu.com
State New
Headers show
Series Fix coccicheck warnings | expand

Commit Message

Zhijian Li (Fujitsu) Jan. 16, 2024, 4:51 a.m. UTC
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/fnic/fnic_attrs.c:17:8-16: WARNING: please use sysfs_emit
> ./drivers/scsi/fnic/fnic_attrs.c:23:8-16: WARNING: please use sysfs_emit
> ./drivers/scsi/fnic/fnic_attrs.c:31:8-16: WARNING: please use sysfs_emit

No functional change intended

CC: Satish Kharat <satishkh@cisco.com>
CC: Sesidhar Baddela <sebaddel@cisco.com>
CC: Karan Tilak Kumar <kartilak@cisco.com>
CC: "James E.J. Bottomley" <jejb@linux.ibm.com>
CC: "Martin K. Petersen" <martin.petersen@oracle.com>
CC: linux-scsi@vger.kernel.org
Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
---
 drivers/scsi/fnic/fnic_attrs.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

Comments

Karan Tilak Kumar (kartilak) Jan. 18, 2024, 11:24 p.m. UTC | #1
On Monday, January 15, 2024 8:52 PM, Li Zhijian <lizhijian@fujitsu.com> wrote:
>
> 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/fnic/fnic_attrs.c:17:8-16: WARNING: please use
> > sysfs_emit
> > ./drivers/scsi/fnic/fnic_attrs.c:23:8-16: WARNING: please use
> > sysfs_emit
> > ./drivers/scsi/fnic/fnic_attrs.c:31:8-16: WARNING: please use
> > sysfs_emit
>
> No functional change intended
>
> CC: Satish Kharat <satishkh@cisco.com>
> CC: Sesidhar Baddela <sebaddel@cisco.com>
> CC: Karan Tilak Kumar <kartilak@cisco.com>
> CC: "James E.J. Bottomley" <jejb@linux.ibm.com>
> CC: "Martin K. Petersen" <martin.petersen@oracle.com>
> CC: linux-scsi@vger.kernel.org
> Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
> ---
> drivers/scsi/fnic/fnic_attrs.c | 7 +++----
> 1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/scsi/fnic/fnic_attrs.c b/drivers/scsi/fnic/fnic_attrs.c index a61e0c5e6506..0c5e57c7e322 100644
> --- a/drivers/scsi/fnic/fnic_attrs.c
> +++ b/drivers/scsi/fnic/fnic_attrs.c
> @@ -14,13 +14,13 @@ static ssize_t fnic_show_state(struct device *dev,
> struct fc_lport *lp = shost_priv(class_to_shost(dev));
> struct fnic *fnic = lport_priv(lp);
>
> -     return snprintf(buf, PAGE_SIZE, "%s\n", fnic_state_str[fnic->state]);
> +     return sysfs_emit(buf, "%s\n", fnic_state_str[fnic->state]);
> }
>
> static ssize_t fnic_show_drv_version(struct device *dev,
> struct device_attribute *attr, char *buf)  {
> -     return snprintf(buf, PAGE_SIZE, "%s\n", DRV_VERSION);
> +     return sysfs_emit(buf, "%s\n", DRV_VERSION);
> }
>
> static ssize_t fnic_show_link_state(struct device *dev, @@ -28,8 +28,7 @@ static ssize_t fnic_show_link_state(struct device *dev,  {
> struct fc_lport *lp = shost_priv(class_to_shost(dev));
>
> -     return snprintf(buf, PAGE_SIZE, "%s\n", (lp->link_up)
> -                     ? "Link Up" : "Link Down");
> +     return sysfs_emit(buf, "%s\n", (lp->link_up) ? "Link Up" : "Link
> +Down");
> }
>
> static DEVICE_ATTR(fnic_state, S_IRUGO, fnic_show_state, NULL);
> --
> 2.29.2
>
>

Looks good to me.

Reviewed-by: Karan Tilak Kumar <kartilak@cisco.com>

Regards,
Karan
diff mbox series

Patch

diff --git a/drivers/scsi/fnic/fnic_attrs.c b/drivers/scsi/fnic/fnic_attrs.c
index a61e0c5e6506..0c5e57c7e322 100644
--- a/drivers/scsi/fnic/fnic_attrs.c
+++ b/drivers/scsi/fnic/fnic_attrs.c
@@ -14,13 +14,13 @@  static ssize_t fnic_show_state(struct device *dev,
 	struct fc_lport *lp = shost_priv(class_to_shost(dev));
 	struct fnic *fnic = lport_priv(lp);
 
-	return snprintf(buf, PAGE_SIZE, "%s\n", fnic_state_str[fnic->state]);
+	return sysfs_emit(buf, "%s\n", fnic_state_str[fnic->state]);
 }
 
 static ssize_t fnic_show_drv_version(struct device *dev,
 				     struct device_attribute *attr, char *buf)
 {
-	return snprintf(buf, PAGE_SIZE, "%s\n", DRV_VERSION);
+	return sysfs_emit(buf, "%s\n", DRV_VERSION);
 }
 
 static ssize_t fnic_show_link_state(struct device *dev,
@@ -28,8 +28,7 @@  static ssize_t fnic_show_link_state(struct device *dev,
 {
 	struct fc_lport *lp = shost_priv(class_to_shost(dev));
 
-	return snprintf(buf, PAGE_SIZE, "%s\n", (lp->link_up)
-			? "Link Up" : "Link Down");
+	return sysfs_emit(buf, "%s\n", (lp->link_up) ? "Link Up" : "Link Down");
 }
 
 static DEVICE_ATTR(fnic_state, S_IRUGO, fnic_show_state, NULL);