Skip to contentSkip to conversation

qede: cleanup printing in qede_log_probe()

PATCH In review Dan Carpenter 2 participants 3 messages Sep 16, 2021 – Sep 17, 2021

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qede: cleanup printing in qede_log_probe()

This code use strlen(buf) to find the number of characters printed. That's sort of ugly and unnecessary because we can just use the return from scnprintf() instead.

Also since strlen() does not count the NUL terminator, that means "QEDE_FW_VER_STR_SIZE - strlen(buf)" is never going to be zero so that condition can be removed.

---
 drivers/net/ethernet/qlogic/qede/qede_main.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/net/ethernet/qlogic/qede/qede_main.c +4 -5
index 9837bdb89cd4..e188ff5277a5 100644
@@ -1087,9 +1087,9 @@ static void qede_log_probe(struct qede_dev *edev)
 {
 	struct qed_dev_info *p_dev_info = &edev->dev_info.common;
 	u8 buf[QEDE_FW_VER_STR_SIZE];
-	size_t left_size;
+	int off;
 
-	snprintf(buf, QEDE_FW_VER_STR_SIZE,
+	off = scnprintf(buf, QEDE_FW_VER_STR_SIZE,
 		 "Storm FW %d.%d.%d.%d, Management FW %d.%d.%d.%d",
 		 p_dev_info->fw_major, p_dev_info->fw_minor, p_dev_info->fw_rev,
 		 p_dev_info->fw_eng,
@@ -1102,9 +1102,8 @@ static void qede_log_probe(struct qede_dev *edev)
 		 (p_dev_info->mfw_rev & QED_MFW_VERSION_0_MASK) >>
 		 QED_MFW_VERSION_0_OFFSET);
 
-	left_size = QEDE_FW_VER_STR_SIZE - strlen(buf);
-	if (p_dev_info->mbi_version && left_size)
-		snprintf(buf + strlen(buf), left_size,
+	if (p_dev_info->mbi_version)
+		off += scnprintf(buf + off, sizeof(buf) - off,
 			 " [MBI %d.%d.%d]",
 			 (p_dev_info->mbi_version & QED_MBI_VERSION_2_MASK) >>
 			 QED_MBI_VERSION_2_OFFSET,
Signature · 1 line
2.20.1
maintainer
#1 lore raw
Quoted 19 lines · On Thu, 16 Sep 2021 16:54:15 +0300 Dan Carpenter wrote:

This code use strlen(buf) to find the number of characters printed. That's sort of ugly and unnecessary because we can just use the return from scnprintf() instead.

Also since strlen() does not count the NUL terminator, that means "QEDE_FW_VER_STR_SIZE - strlen(buf)" is never going to be zero so that condition can be removed.

---
 drivers/net/ethernet/qlogic/qede/qede_main.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/net/ethernet/qlogic/qede/qede_main.c +0 -0
index 9837bdb89cd4..e188ff5277a5 100644
@@ -1087,9 +1087,9 @@ static void qede_log_probe(struct qede_dev *edev)
 {

drivers/net/ethernet/qlogic/qede/qede_main.c static void qede_log_probe(struct qede_dev *edev) · line 1095

Quoted 10 lines
drivers/net/ethernet/qlogic/qede/qede_main.c +2 -2
 	struct qed_dev_info *p_dev_info = &edev->dev_info.common;
 	u8 buf[QEDE_FW_VER_STR_SIZE];
-	size_t left_size;
+	int off;
 
-	snprintf(buf, QEDE_FW_VER_STR_SIZE,
+	off = scnprintf(buf, QEDE_FW_VER_STR_SIZE,
 		 "Storm FW %d.%d.%d.%d, Management FW %d.%d.%d.%d",
 		 p_dev_info->fw_major, p_dev_info->fw_minor, p_dev_info->fw_rev,
 		 p_dev_info->fw_eng,

Why not adjust the continuation lines? checkpatch is not happy.

#2 lore raw
Quoted 25 lines · Jakub Kicinski
Quoted 24 lines · On Thu, 16 Sep 2021 16:54:15 +0300 Dan Carpenter wrote:

This code use strlen(buf) to find the number of characters printed. That's sort of ugly and unnecessary because we can just use the return from scnprintf() instead.

Also since strlen() does not count the NUL terminator, that means "QEDE_FW_VER_STR_SIZE - strlen(buf)" is never going to be zero so that condition can be removed.

---
 drivers/net/ethernet/qlogic/qede/qede_main.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/net/ethernet/qlogic/qede/qede_main.c +1 -1
index 9837bdb89cd4..e188ff5277a5 100644
@@ -1087,9 +1087,9 @@ static void qede_log_probe(struct qede_dev *edev)
 {
 	struct qed_dev_info *p_dev_info = &edev->dev_info.common;
 	u8 buf[QEDE_FW_VER_STR_SIZE];
-	size_t left_size;
+	int off;
 
Quoted 7 lines

drivers/net/ethernet/qlogic/qede/qede_main.c static void qede_log_probe(struct qede_dev *edev) · line 1095

Quoted 5 lines
drivers/net/ethernet/qlogic/qede/qede_main.c +1 -1
-	snprintf(buf, QEDE_FW_VER_STR_SIZE,
+	off = scnprintf(buf, QEDE_FW_VER_STR_SIZE,
 		 "Storm FW %d.%d.%d.%d, Management FW %d.%d.%d.%d",
 		 p_dev_info->fw_major, p_dev_info->fw_minor, p_dev_info->fw_rev,
 		 p_dev_info->fw_eng,

Why not adjust the continuation lines? checkpatch is not happy.

Sorry about that. I'll resend.

regards,
dan carpenter