lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <Y9gkeqfw/v6/UGxA@ubun2204.myguest.virtualbox.org>
Date:   Tue, 31 Jan 2023 01:41:38 +0530
From:   Deepak R Varma <drv@...lo.com>
To:     Hannes Reinecke <hare@...e.de>,
        "James E.J. Bottomley" <jejb@...ux.ibm.com>,
        "Martin K. Petersen" <martin.petersen@...cle.com>,
        linux-scsi@...r.kernel.org, linux-kernel@...r.kernel.org
Cc:     Saurabh Singh Sengar <ssengar@...rosoft.com>,
        Praveen Kumar <kumarpraveen@...ux.microsoft.com>,
        Deepak R Varma <drv@...lo.com>
Subject: [PATCH] scsi: fcoe: Use sysfs_emit in show function callback

According to Documentation/filesystems/sysfs.rst, show() callback
function should only use sysfs_emit() or sysfs_emit_at() instead
of sprint() family functions when formatting the device attribute
values to be returned to user space.
Issue identified using the device_attr_show.cocci Coccinelle script.

Signed-off-by: Deepak R Varma <drv@...lo.com>
---
 drivers/scsi/fcoe/fcoe_sysfs.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
index 6260aa5ea6af..9c50971c4bba 100644
--- a/drivers/scsi/fcoe/fcoe_sysfs.c
+++ b/drivers/scsi/fcoe/fcoe_sysfs.c
@@ -250,7 +250,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);
 
@@ -265,8 +265,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,
@@ -373,8 +372,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,
@@ -412,7 +410,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,
@@ -455,7 +453,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,
@@ -482,7 +480,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.34.1



Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ