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>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220927113437.259529-1-zhang.songyi@zte.com.cn>
Date:   Tue, 27 Sep 2022 11:34:37 +0000
From:   zhangsongyi.cgel@...il.com
To:     martin.petersen@...cle.com
Cc:     zhang.songyi@....com.cn, mgurtovoy@...dia.com,
        michael.christie@...cle.com, linux-scsi@...r.kernel.org,
        target-devel@...r.kernel.org, linux-kernel@...r.kernel.org,
        Zeal Robot <zealci@....com.cn>
Subject: [PATCH linux-next] scsi: target: use sysfs_emit() to instead of snprintf()

From: zhang songyi <zhang.songyi@....com.cn>

Follow the advice of the Documentation/filesystems/sysfs.rst and show()
should only use sysfs_emit() or sysfs_emit_at() when formatting the value
to be returned to user space.

Reported-by: Zeal Robot <zealci@....com.cn>
Signed-off-by: zhang songyi <zhang.songyi@....com.cn>
---
 drivers/target/iscsi/iscsi_target_stat.c | 94 ++++++++++++------------
 1 file changed, 47 insertions(+), 47 deletions(-)

diff --git a/drivers/target/iscsi/iscsi_target_stat.c b/drivers/target/iscsi/iscsi_target_stat.c
index 367c6468b8e1..64a3fa7965a6 100644
--- a/drivers/target/iscsi/iscsi_target_stat.c
+++ b/drivers/target/iscsi/iscsi_target_stat.c
@@ -50,39 +50,39 @@ static struct iscsi_tiqn *iscsi_instance_tiqn(struct config_item *item)
 static ssize_t iscsi_stat_instance_inst_show(struct config_item *item,
 		char *page)
 {
-	return snprintf(page, PAGE_SIZE, "%u\n",
+	return sysfs_emit(page, "%u\n",
 			iscsi_instance_tiqn(item)->tiqn_index);
 }
 
 static ssize_t iscsi_stat_instance_min_ver_show(struct config_item *item,
 		char *page)
 {
-	return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_DRAFT20_VERSION);
+	return sysfs_emit(page, "%u\n", ISCSI_DRAFT20_VERSION);
 }
 
 static ssize_t iscsi_stat_instance_max_ver_show(struct config_item *item,
 		char *page)
 {
-	return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_DRAFT20_VERSION);
+	return sysfs_emit(page, "%u\n", ISCSI_DRAFT20_VERSION);
 }
 
 static ssize_t iscsi_stat_instance_portals_show(struct config_item *item,
 		char *page)
 {
-	return snprintf(page, PAGE_SIZE, "%u\n",
+	return sysfs_emit(page, "%u\n",
 			iscsi_instance_tiqn(item)->tiqn_num_tpg_nps);
 }
 
 static ssize_t iscsi_stat_instance_nodes_show(struct config_item *item,
 		char *page)
 {
-	return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_INST_NUM_NODES);
+	return sysfs_emit(page, "%u\n", ISCSI_INST_NUM_NODES);
 }
 
 static ssize_t iscsi_stat_instance_sessions_show(struct config_item *item,
 		char *page)
 {
-	return snprintf(page, PAGE_SIZE, "%u\n",
+	return sysfs_emit(page, "%u\n",
 		iscsi_instance_tiqn(item)->tiqn_nsessions);
 }
 
@@ -99,7 +99,7 @@ static ssize_t iscsi_stat_instance_fail_sess_show(struct config_item *item,
 			  sess_err->pdu_format_errors);
 	spin_unlock_bh(&sess_err->lock);
 
-	return snprintf(page, PAGE_SIZE, "%u\n", sess_err_count);
+	return sysfs_emit(page, "%u\n", sess_err_count);
 }
 
 static ssize_t iscsi_stat_instance_fail_type_show(struct config_item *item,
@@ -108,7 +108,7 @@ static ssize_t iscsi_stat_instance_fail_type_show(struct config_item *item,
 	struct iscsi_tiqn *tiqn = iscsi_instance_tiqn(item);
 	struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats;
 
-	return snprintf(page, PAGE_SIZE, "%u\n",
+	return sysfs_emit(page, "%u\n",
 			sess_err->last_sess_failure_type);
 }
 
@@ -118,7 +118,7 @@ static ssize_t iscsi_stat_instance_fail_rem_name_show(struct config_item *item,
 	struct iscsi_tiqn *tiqn = iscsi_instance_tiqn(item);
 	struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats;
 
-	return snprintf(page, PAGE_SIZE, "%s\n",
+	return sysfs_emit(page, "%s\n",
 			sess_err->last_sess_fail_rem_name[0] ?
 			sess_err->last_sess_fail_rem_name : NONE);
 }
@@ -126,25 +126,25 @@ static ssize_t iscsi_stat_instance_fail_rem_name_show(struct config_item *item,
 static ssize_t iscsi_stat_instance_disc_time_show(struct config_item *item,
 		char *page)
 {
-	return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_DISCONTINUITY_TIME);
+	return sysfs_emit(page, "%u\n", ISCSI_DISCONTINUITY_TIME);
 }
 
 static ssize_t iscsi_stat_instance_description_show(struct config_item *item,
 		char *page)
 {
-	return snprintf(page, PAGE_SIZE, "%s\n", ISCSI_INST_DESCR);
+	return sysfs_emit(page, "%s\n", ISCSI_INST_DESCR);
 }
 
 static ssize_t iscsi_stat_instance_vendor_show(struct config_item *item,
 		char *page)
 {
-	return snprintf(page, PAGE_SIZE, "Datera, Inc. iSCSI-Target\n");
+	return sysfs_emit(page, "Datera, Inc. iSCSI-Target\n");
 }
 
 static ssize_t iscsi_stat_instance_version_show(struct config_item *item,
 		char *page)
 {
-	return snprintf(page, PAGE_SIZE, "%s\n", ISCSIT_VERSION);
+	return sysfs_emit(page, "%s\n", ISCSIT_VERSION);
 }
 
 CONFIGFS_ATTR_RO(iscsi_stat_instance_, inst);
@@ -196,7 +196,7 @@ static struct iscsi_tiqn *iscsi_sess_err_tiqn(struct config_item *item)
 static ssize_t iscsi_stat_sess_err_inst_show(struct config_item *item,
 		char *page)
 {
-	return snprintf(page, PAGE_SIZE, "%u\n",
+	return sysfs_emit(page, "%u\n",
 		iscsi_sess_err_tiqn(item)->tiqn_index);
 }
 
@@ -206,7 +206,7 @@ static ssize_t iscsi_stat_sess_err_digest_errors_show(struct config_item *item,
 	struct iscsi_tiqn *tiqn = iscsi_sess_err_tiqn(item);
 	struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats;
 
-	return snprintf(page, PAGE_SIZE, "%u\n", sess_err->digest_errors);
+	return sysfs_emit(page, "%u\n", sess_err->digest_errors);
 }
 
 static ssize_t iscsi_stat_sess_err_cxn_errors_show(struct config_item *item,
@@ -215,7 +215,7 @@ static ssize_t iscsi_stat_sess_err_cxn_errors_show(struct config_item *item,
 	struct iscsi_tiqn *tiqn = iscsi_sess_err_tiqn(item);
 	struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats;
 
-	return snprintf(page, PAGE_SIZE, "%u\n", sess_err->cxn_timeout_errors);
+	return sysfs_emit(page, "%u\n", sess_err->cxn_timeout_errors);
 }
 
 static ssize_t iscsi_stat_sess_err_format_errors_show(struct config_item *item,
@@ -224,7 +224,7 @@ static ssize_t iscsi_stat_sess_err_format_errors_show(struct config_item *item,
 	struct iscsi_tiqn *tiqn = iscsi_sess_err_tiqn(item);
 	struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats;
 
-	return snprintf(page, PAGE_SIZE, "%u\n", sess_err->pdu_format_errors);
+	return sysfs_emit(page, "%u\n", sess_err->pdu_format_errors);
 }
 
 CONFIGFS_ATTR_RO(iscsi_stat_sess_err_, inst);
@@ -258,14 +258,14 @@ static struct iscsi_tiqn *iscsi_tgt_attr_tiqn(struct config_item *item)
 static ssize_t iscsi_stat_tgt_attr_inst_show(struct config_item *item,
 		char *page)
 {
-	return snprintf(page, PAGE_SIZE, "%u\n",
+	return sysfs_emit(page, "%u\n",
 			iscsi_tgt_attr_tiqn(item)->tiqn_index);
 }
 
 static ssize_t iscsi_stat_tgt_attr_indx_show(struct config_item *item,
 		char *page)
 {
-	return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_NODE_INDEX);
+	return sysfs_emit(page, "%u\n", ISCSI_NODE_INDEX);
 }
 
 static ssize_t iscsi_stat_tgt_attr_login_fails_show(struct config_item *item,
@@ -281,7 +281,7 @@ static ssize_t iscsi_stat_tgt_attr_login_fails_show(struct config_item *item,
 			lstat->other_fails);
 	spin_unlock(&lstat->lock);
 
-	return snprintf(page, PAGE_SIZE, "%u\n", fail_count);
+	return sysfs_emit(page, "%u\n", fail_count);
 }
 
 static ssize_t iscsi_stat_tgt_attr_last_fail_time_show(struct config_item *item,
@@ -297,7 +297,7 @@ static ssize_t iscsi_stat_tgt_attr_last_fail_time_show(struct config_item *item,
 				INITIAL_JIFFIES) * 100 / HZ) : 0;
 	spin_unlock(&lstat->lock);
 
-	return snprintf(page, PAGE_SIZE, "%u\n", last_fail_time);
+	return sysfs_emit(page, "%u\n", last_fail_time);
 }
 
 static ssize_t iscsi_stat_tgt_attr_last_fail_type_show(struct config_item *item,
@@ -311,7 +311,7 @@ static ssize_t iscsi_stat_tgt_attr_last_fail_type_show(struct config_item *item,
 	last_fail_type = lstat->last_fail_type;
 	spin_unlock(&lstat->lock);
 
-	return snprintf(page, PAGE_SIZE, "%u\n", last_fail_type);
+	return sysfs_emit(page, "%u\n", last_fail_type);
 }
 
 static ssize_t iscsi_stat_tgt_attr_fail_intr_name_show(struct config_item *item,
@@ -326,7 +326,7 @@ static ssize_t iscsi_stat_tgt_attr_fail_intr_name_show(struct config_item *item,
 				lstat->last_intr_fail_name : NONE);
 	spin_unlock(&lstat->lock);
 
-	return snprintf(page, PAGE_SIZE, "%s\n", buf);
+	return sysfs_emit(page, "%s\n", buf);
 }
 
 static ssize_t iscsi_stat_tgt_attr_fail_intr_addr_type_show(struct config_item *item,
@@ -338,9 +338,9 @@ static ssize_t iscsi_stat_tgt_attr_fail_intr_addr_type_show(struct config_item *
 
 	spin_lock(&lstat->lock);
 	if (lstat->last_intr_fail_ip_family == AF_INET6)
-		ret = snprintf(page, PAGE_SIZE, "ipv6\n");
+		ret = sysfs_emit(page, "ipv6\n");
 	else
-		ret = snprintf(page, PAGE_SIZE, "ipv4\n");
+		ret = sysfs_emit(page, "ipv4\n");
 	spin_unlock(&lstat->lock);
 
 	return ret;
@@ -354,7 +354,7 @@ static ssize_t iscsi_stat_tgt_attr_fail_intr_addr_show(struct config_item *item,
 	int ret;
 
 	spin_lock(&lstat->lock);
-	ret = snprintf(page, PAGE_SIZE, "%pISc\n", &lstat->last_intr_fail_sockaddr);
+	ret = sysfs_emit(page, "%pISc\n", &lstat->last_intr_fail_sockaddr);
 	spin_unlock(&lstat->lock);
 
 	return ret;
@@ -398,14 +398,14 @@ static struct iscsi_tiqn *iscsi_login_stat_tiqn(struct config_item *item)
 
 static ssize_t iscsi_stat_login_inst_show(struct config_item *item, char *page)
 {
-	return snprintf(page, PAGE_SIZE, "%u\n",
+	return sysfs_emit(page, "%u\n",
 		iscsi_login_stat_tiqn(item)->tiqn_index);
 }
 
 static ssize_t iscsi_stat_login_indx_show(struct config_item *item,
 		char *page)
 {
-	return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_NODE_INDEX);
+	return sysfs_emit(page, "%u\n", ISCSI_NODE_INDEX);
 }
 
 static ssize_t iscsi_stat_login_accepts_show(struct config_item *item,
@@ -416,7 +416,7 @@ static ssize_t iscsi_stat_login_accepts_show(struct config_item *item,
 	ssize_t ret;
 
 	spin_lock(&lstat->lock);
-	ret = snprintf(page, PAGE_SIZE, "%u\n", lstat->accepts);
+	ret = sysfs_emit(page, "%u\n", lstat->accepts);
 	spin_unlock(&lstat->lock);
 
 	return ret;
@@ -430,7 +430,7 @@ static ssize_t iscsi_stat_login_other_fails_show(struct config_item *item,
 	ssize_t ret;
 
 	spin_lock(&lstat->lock);
-	ret = snprintf(page, PAGE_SIZE, "%u\n", lstat->other_fails);
+	ret = sysfs_emit(page, "%u\n", lstat->other_fails);
 	spin_unlock(&lstat->lock);
 
 	return ret;
@@ -444,7 +444,7 @@ static ssize_t iscsi_stat_login_redirects_show(struct config_item *item,
 	ssize_t ret;
 
 	spin_lock(&lstat->lock);
-	ret = snprintf(page, PAGE_SIZE, "%u\n", lstat->redirects);
+	ret = sysfs_emit(page, "%u\n", lstat->redirects);
 	spin_unlock(&lstat->lock);
 
 	return ret;
@@ -458,7 +458,7 @@ static ssize_t iscsi_stat_login_authorize_fails_show(struct config_item *item,
 	ssize_t ret;
 
 	spin_lock(&lstat->lock);
-	ret = snprintf(page, PAGE_SIZE, "%u\n", lstat->authorize_fails);
+	ret = sysfs_emit(page, "%u\n", lstat->authorize_fails);
 	spin_unlock(&lstat->lock);
 
 	return ret;
@@ -472,7 +472,7 @@ static ssize_t iscsi_stat_login_authenticate_fails_show(
 	ssize_t ret;
 
 	spin_lock(&lstat->lock);
-	ret = snprintf(page, PAGE_SIZE, "%u\n", lstat->authenticate_fails);
+	ret = sysfs_emit(page, "%u\n", lstat->authenticate_fails);
 	spin_unlock(&lstat->lock);
 
 	return ret;
@@ -486,7 +486,7 @@ static ssize_t iscsi_stat_login_negotiate_fails_show(struct config_item *item,
 	ssize_t ret;
 
 	spin_lock(&lstat->lock);
-	ret = snprintf(page, PAGE_SIZE, "%u\n", lstat->negotiate_fails);
+	ret = sysfs_emit(page, "%u\n", lstat->negotiate_fails);
 	spin_unlock(&lstat->lock);
 
 	return ret;
@@ -530,13 +530,13 @@ static struct iscsi_tiqn *iscsi_logout_stat_tiqn(struct config_item *item)
 
 static ssize_t iscsi_stat_logout_inst_show(struct config_item *item, char *page)
 {
-	return snprintf(page, PAGE_SIZE, "%u\n",
+	return sysfs_emit(page, "%u\n",
 		iscsi_logout_stat_tiqn(item)->tiqn_index);
 }
 
 static ssize_t iscsi_stat_logout_indx_show(struct config_item *item, char *page)
 {
-	return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_NODE_INDEX);
+	return sysfs_emit(page, "%u\n", ISCSI_NODE_INDEX);
 }
 
 static ssize_t iscsi_stat_logout_normal_logouts_show(struct config_item *item,
@@ -545,7 +545,7 @@ static ssize_t iscsi_stat_logout_normal_logouts_show(struct config_item *item,
 	struct iscsi_tiqn *tiqn = iscsi_logout_stat_tiqn(item);
 	struct iscsi_logout_stats *lstats = &tiqn->logout_stats;
 
-	return snprintf(page, PAGE_SIZE, "%u\n", lstats->normal_logouts);
+	return sysfs_emit(page, "%u\n", lstats->normal_logouts);
 }
 
 static ssize_t iscsi_stat_logout_abnormal_logouts_show(struct config_item *item,
@@ -554,7 +554,7 @@ static ssize_t iscsi_stat_logout_abnormal_logouts_show(struct config_item *item,
 	struct iscsi_tiqn *tiqn = iscsi_logout_stat_tiqn(item);
 	struct iscsi_logout_stats *lstats = &tiqn->logout_stats;
 
-	return snprintf(page, PAGE_SIZE, "%u\n", lstats->abnormal_logouts);
+	return sysfs_emit(page, "%u\n", lstats->abnormal_logouts);
 }
 
 CONFIGFS_ATTR_RO(iscsi_stat_logout_, inst);
@@ -592,7 +592,7 @@ static ssize_t iscsi_stat_sess_inst_show(struct config_item *item, char *page)
 	struct iscsi_tiqn *tiqn = container_of(wwn,
 			struct iscsi_tiqn, tiqn_wwn);
 
-	return snprintf(page, PAGE_SIZE, "%u\n", tiqn->tiqn_index);
+	return sysfs_emit(page, "%u\n", tiqn->tiqn_index);
 }
 
 static ssize_t iscsi_stat_sess_node_show(struct config_item *item, char *page)
@@ -608,7 +608,7 @@ static ssize_t iscsi_stat_sess_node_show(struct config_item *item, char *page)
 	if (se_sess) {
 		sess = se_sess->fabric_sess_ptr;
 		if (sess)
-			ret = snprintf(page, PAGE_SIZE, "%u\n",
+			ret = sysfs_emit(page, "%u\n",
 				sess->sess_ops->SessionType ? 0 : ISCSI_NODE_INDEX);
 	}
 	spin_unlock_bh(&se_nacl->nacl_sess_lock);
@@ -629,7 +629,7 @@ static ssize_t iscsi_stat_sess_indx_show(struct config_item *item, char *page)
 	if (se_sess) {
 		sess = se_sess->fabric_sess_ptr;
 		if (sess)
-			ret = snprintf(page, PAGE_SIZE, "%u\n",
+			ret = sysfs_emit(page, "%u\n",
 					sess->session_index);
 	}
 	spin_unlock_bh(&se_nacl->nacl_sess_lock);
@@ -651,7 +651,7 @@ static ssize_t iscsi_stat_sess_cmd_pdus_show(struct config_item *item,
 	if (se_sess) {
 		sess = se_sess->fabric_sess_ptr;
 		if (sess)
-			ret = snprintf(page, PAGE_SIZE, "%lu\n",
+			ret = sysfs_emit(page, "%lu\n",
 				       atomic_long_read(&sess->cmd_pdus));
 	}
 	spin_unlock_bh(&se_nacl->nacl_sess_lock);
@@ -673,7 +673,7 @@ static ssize_t iscsi_stat_sess_rsp_pdus_show(struct config_item *item,
 	if (se_sess) {
 		sess = se_sess->fabric_sess_ptr;
 		if (sess)
-			ret = snprintf(page, PAGE_SIZE, "%lu\n",
+			ret = sysfs_emit(page, "%lu\n",
 				       atomic_long_read(&sess->rsp_pdus));
 	}
 	spin_unlock_bh(&se_nacl->nacl_sess_lock);
@@ -695,7 +695,7 @@ static ssize_t iscsi_stat_sess_txdata_octs_show(struct config_item *item,
 	if (se_sess) {
 		sess = se_sess->fabric_sess_ptr;
 		if (sess)
-			ret = snprintf(page, PAGE_SIZE, "%lu\n",
+			ret = sysfs_emit(page, "%lu\n",
 				       atomic_long_read(&sess->tx_data_octets));
 	}
 	spin_unlock_bh(&se_nacl->nacl_sess_lock);
@@ -717,7 +717,7 @@ static ssize_t iscsi_stat_sess_rxdata_octs_show(struct config_item *item,
 	if (se_sess) {
 		sess = se_sess->fabric_sess_ptr;
 		if (sess)
-			ret = snprintf(page, PAGE_SIZE, "%lu\n",
+			ret = sysfs_emit(page, "%lu\n",
 				       atomic_long_read(&sess->rx_data_octets));
 	}
 	spin_unlock_bh(&se_nacl->nacl_sess_lock);
@@ -739,7 +739,7 @@ static ssize_t iscsi_stat_sess_conn_digest_errors_show(struct config_item *item,
 	if (se_sess) {
 		sess = se_sess->fabric_sess_ptr;
 		if (sess)
-			ret = snprintf(page, PAGE_SIZE, "%lu\n",
+			ret = sysfs_emit(page, "%lu\n",
 				       atomic_long_read(&sess->conn_digest_errors));
 	}
 	spin_unlock_bh(&se_nacl->nacl_sess_lock);
@@ -761,7 +761,7 @@ static ssize_t iscsi_stat_sess_conn_timeout_errors_show(
 	if (se_sess) {
 		sess = se_sess->fabric_sess_ptr;
 		if (sess)
-			ret = snprintf(page, PAGE_SIZE, "%lu\n",
+			ret = sysfs_emit(page, "%lu\n",
 				       atomic_long_read(&sess->conn_timeout_errors));
 	}
 	spin_unlock_bh(&se_nacl->nacl_sess_lock);
-- 
2.25.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ