[PATCH v2 05/25] scsi: fcoe: Convert sprintf() family to sysfs_emit() family (part 1)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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().

sprintf() and scnprintf() will be converted as well if they have.

Generally, this patch is generated by
make coccicheck M=<path/to/file> MODE=patch \
COCCI=scripts/coccinelle/api/device_attr_show.cocci

No functional change intended

CC: Hannes Reinecke <hare@xxxxxxx>
CC: "James E.J. Bottomley" <jejb@xxxxxxxxxxxxx>
CC: "Martin K. Petersen" <martin.petersen@xxxxxxxxxx>
CC: linux-scsi@xxxxxxxxxxxxxxx
Signed-off-by: Li Zhijian <lizhijian@xxxxxxxxxxx>
---
This is a part of the work "Fix coccicheck device_attr_show warnings"[1]
Split them per subsystem so that the maintainer can review it easily
[1] https://lore.kernel.org/lkml/20240116041129.3937800-1-lizhijian@xxxxxxxxxxx/
---
 drivers/scsi/fcoe/fcoe_sysfs.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
index 453665ac6020..46a2f7f0669f 100644
--- a/drivers/scsi/fcoe/fcoe_sysfs.c
+++ b/drivers/scsi/fcoe/fcoe_sysfs.c
@@ -228,7 +228,6 @@ static char *fcf_state_names[] = {
 	[ FCOE_FCF_STATE_CONNECTED ]    = "Connected",
 };
 fcoe_enum_name_search(fcf_state, fcf_state, fcf_state_names)
-#define FCOE_FCF_STATE_MAX_NAMELEN 50
 
 static ssize_t show_fcf_state(struct device *dev,
 			      struct device_attribute *attr,
@@ -239,7 +238,7 @@ static ssize_t show_fcf_state(struct device *dev,
 	name = get_fcoe_fcf_state_name(fcf->state);
 	if (!name)
 		return -EINVAL;
-	return snprintf(buf, FCOE_FCF_STATE_MAX_NAMELEN, "%s\n", name);
+	return sysfs_emit(buf, "%s\n", name);
 }
 static FCOE_DEVICE_ATTR(fcf, state, S_IRUGO, show_fcf_state, NULL);
 
@@ -254,8 +253,7 @@ static ssize_t show_ctlr_mode(struct device *dev,
 	name = get_fcoe_ctlr_mode_name(ctlr->mode);
 	if (!name)
 		return -EINVAL;
-	return snprintf(buf, FCOE_MAX_MODENAME_LEN,
-			"%s\n", name);
+	return sysfs_emit(buf, "%s\n", name);
 }
 
 static ssize_t store_ctlr_mode(struct device *dev,
@@ -345,7 +343,6 @@ static char *ctlr_enabled_state_names[] = {
 };
 fcoe_enum_name_search(ctlr_enabled_state, ctlr_enabled_state,
 		      ctlr_enabled_state_names)
-#define FCOE_CTLR_ENABLED_MAX_NAMELEN 50
 
 static ssize_t show_ctlr_enabled_state(struct device *dev,
 				       struct device_attribute *attr,
@@ -357,8 +354,7 @@ static ssize_t show_ctlr_enabled_state(struct device *dev,
 	name = get_fcoe_ctlr_enabled_state_name(ctlr->enabled);
 	if (!name)
 		return -EINVAL;
-	return snprintf(buf, FCOE_CTLR_ENABLED_MAX_NAMELEN,
-			"%s\n", name);
+	return sysfs_emit(buf, "%s\n", name);
 }
 
 static FCOE_DEVICE_ATTR(ctlr, enabled, S_IRUGO | S_IWUSR,
@@ -396,7 +392,7 @@ static ssize_t show_ctlr_fip_resp(struct device *dev,
 	struct fcoe_ctlr_device *ctlr = dev_to_ctlr(dev);
 	struct fcoe_ctlr *fip = fcoe_ctlr_device_priv(ctlr);
 
-	return sprintf(buf, "%d\n", fip->fip_resp ? 1 : 0);
+	return sysfs_emit(buf, "%d\n", fip->fip_resp ? 1 : 0);
 }
 
 static FCOE_DEVICE_ATTR(ctlr, fip_vlan_responder, S_IRUGO | S_IWUSR,
@@ -439,7 +435,7 @@ static ssize_t show_ctlr_r_a_tov(struct device *dev,
 	struct fcoe_ctlr_device *ctlr_dev = dev_to_ctlr(dev);
 	struct fcoe_ctlr *ctlr = fcoe_ctlr_device_priv(ctlr_dev);
 
-	return sprintf(buf, "%d\n", ctlr->lp->r_a_tov);
+	return sysfs_emit(buf, "%d\n", ctlr->lp->r_a_tov);
 }
 
 static FCOE_DEVICE_ATTR(ctlr, r_a_tov, S_IRUGO | S_IWUSR,
@@ -466,7 +462,7 @@ static ssize_t show_ctlr_e_d_tov(struct device *dev,
 	struct fcoe_ctlr_device *ctlr_dev = dev_to_ctlr(dev);
 	struct fcoe_ctlr *ctlr = fcoe_ctlr_device_priv(ctlr_dev);
 
-	return sprintf(buf, "%d\n", ctlr->lp->e_d_tov);
+	return sysfs_emit(buf, "%d\n", ctlr->lp->e_d_tov);
 }
 
 static FCOE_DEVICE_ATTR(ctlr, e_d_tov, S_IRUGO | S_IWUSR,
-- 
2.29.2





[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [SCSI Target Devel]     [Linux SCSI Target Infrastructure]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Samba]     [Device Mapper]

  Powered by Linux