All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jesse Brandeburg <jesse.brandeburg@intel.com>
To: mkubecek@suse.cz
Cc: netdev@vger.kernel.org, Jesse Brandeburg <jesse.brandeburg@intel.com>
Subject: [PATCH ethtool v2 04/13] ethtool: commonize power related strings
Date: Wed,  7 Dec 2022 17:11:13 -0800	[thread overview]
Message-ID: <20221208011122.2343363-5-jesse.brandeburg@intel.com> (raw)
In-Reply-To: <20221208011122.2343363-1-jesse.brandeburg@intel.com>

When looking into the implementation of the qsfp.h file, I found three
pieces of code all doing the same thing and using similar, but bespoke
strings.

Just make one set of strings for all three places to use. I made an
effort to see if there was any size change due to making this change but
I see no difference.

Signed-off-by: Jesse Brandeburg <jesse.brandeburg@intel.com>
---
 cmis.c       | 10 ++--------
 qsfp.c       | 15 +++++++--------
 sff-common.h |  3 +++
 sfpdiag.c    |  9 ++-------
 4 files changed, 14 insertions(+), 23 deletions(-)

diff --git a/cmis.c b/cmis.c
index d0b62728e998..40ff5e541737 100644
--- a/cmis.c
+++ b/cmis.c
@@ -727,16 +727,10 @@ cmis_show_dom_chan_lvl_rx_power_bank(const struct cmis_memory_map *map,
 
 	for (i = 0; i < CMIS_CHANNELS_PER_BANK; i++) {
 		int chan = bank * CMIS_CHANNELS_PER_BANK + i;
-		char *rx_power_str;
 		char fmt_str[80];
 
-		if (!sd->rx_power_type)
-			rx_power_str = "Receiver signal OMA";
-		else
-			rx_power_str = "Rcvr signal avg optical power";
-
-		snprintf(fmt_str, 80, "%s (Channel %d)", rx_power_str,
-			 chan + 1);
+		snprintf(fmt_str, 80, "%s (Channel %d)", sd->rx_power_type ?
+			 rx_power_average : rx_power_oma, chan + 1);
 		PRINT_xX_PWR(fmt_str, sd->scd[chan].rx_power);
 	}
 }
diff --git a/qsfp.c b/qsfp.c
index fb94202757d3..a79da29de950 100644
--- a/qsfp.c
+++ b/qsfp.c
@@ -798,7 +798,6 @@ out:
 static void sff8636_show_dom(const struct sff8636_memory_map *map)
 {
 	struct sff_diags sd = {0};
-	char *rx_power_string = NULL;
 	char power_string[MAX_DESC_SIZE];
 	int i;
 
@@ -846,14 +845,14 @@ static void sff8636_show_dom(const struct sff8636_memory_map *map)
 		PRINT_xX_PWR(power_string, sd.scd[i].tx_power);
 	}
 
-	if (!sd.rx_power_type)
-		rx_power_string = "Receiver signal OMA";
-	else
-		rx_power_string = "Rcvr signal avg optical power";
-
 	for (i = 0; i < SFF8636_MAX_CHANNEL_NUM; i++) {
-		snprintf(power_string, MAX_DESC_SIZE, "%s(Channel %d)",
-					rx_power_string, i+1);
+		int chars;
+
+		chars = snprintf(power_string, MAX_DESC_SIZE,
+				 sd.rx_power_type ?
+				 rx_power_average : rx_power_oma);
+		snprintf(power_string + chars, MAX_DESC_SIZE - chars,
+			 "(Channel %d)", i + 1);
 		PRINT_xX_PWR(power_string, sd.scd[i].rx_power);
 	}
 
diff --git a/sff-common.h b/sff-common.h
index 2f58f91ab7ff..4fc78cf9ee50 100644
--- a/sff-common.h
+++ b/sff-common.h
@@ -188,6 +188,9 @@ struct sff_diags {
 	struct sff_channel_diags scd[MAX_CHANNEL_NUM];
 };
 
+static const char rx_power_oma[] = "Receiver Signal OMA";
+static const char rx_power_average[] = "Receiver Signal average optical power";
+
 double convert_mw_to_dbm(double mw);
 void sff_show_value_with_unit(const __u8 *id, unsigned int reg,
 			      const char *name, unsigned int mult,
diff --git a/sfpdiag.c b/sfpdiag.c
index 1fa8b7ba8fec..502b6e3bf11e 100644
--- a/sfpdiag.c
+++ b/sfpdiag.c
@@ -242,7 +242,6 @@ static void sff8472_parse_eeprom(const __u8 *id, struct sff_diags *sd)
 void sff8472_show_all(const __u8 *id)
 {
 	struct sff_diags sd = {0};
-	char *rx_power_string = NULL;
 	int i;
 
 	sff8472_parse_eeprom(id, &sd);
@@ -256,12 +255,8 @@ void sff8472_show_all(const __u8 *id)
 	PRINT_BIAS("Laser bias current", sd.bias_cur[MCURR]);
 	PRINT_xX_PWR("Laser output power", sd.tx_power[MCURR]);
 
-	if (!sd.rx_power_type)
-		rx_power_string = "Receiver signal OMA";
-	else
-		rx_power_string = "Receiver signal average optical power";
-
-	PRINT_xX_PWR(rx_power_string, sd.rx_power[MCURR]);
+	PRINT_xX_PWR(sd.rx_power_type ? rx_power_average : rx_power_oma,
+		     sd.rx_power[MCURR]);
 
 	PRINT_TEMP("Module temperature", sd.sfp_temp[MCURR]);
 	PRINT_VCC("Module voltage", sd.sfp_voltage[MCURR]);
-- 
2.31.1


  parent reply	other threads:[~2022-12-08  1:12 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-08  1:11 [PATCH ethtool v2 00/13] ethtool: clean up and fix Jesse Brandeburg
2022-12-08  1:11 ` [PATCH ethtool v2 01/13] ethtool: convert boilerplate licenses to SPDX Jesse Brandeburg
2022-12-08  8:17   ` Michal Kubecek
2022-12-08  1:11 ` [PATCH ethtool v2 02/13] ethtool: fix trivial issue in allocation Jesse Brandeburg
2022-12-08  8:26   ` Michal Kubecek
2022-12-08  1:11 ` [PATCH ethtool v2 03/13] ethtool: disallow passing null to find_option Jesse Brandeburg
2022-12-08  9:14   ` Michal Kubecek
2022-12-08  1:11 ` Jesse Brandeburg [this message]
2022-12-08 10:25   ` [PATCH ethtool v2 04/13] ethtool: commonize power related strings Michal Kubecek
2022-12-08  1:11 ` [PATCH ethtool v2 05/13] ethtool: fix extra warnings Jesse Brandeburg
2022-12-08 10:43   ` Michal Kubecek
2022-12-08  1:11 ` [PATCH ethtool v2 06/13] ethtool: fix uninitialized local variable use Jesse Brandeburg
2022-12-08  2:06   ` Andrew Lunn
2022-12-08  1:11 ` [PATCH ethtool v2 07/13] ethtool: avoid null pointer dereference Jesse Brandeburg
2022-12-08  6:23   ` Michal Kubecek
2022-12-09 17:36     ` Jesse Brandeburg
2022-12-09 18:06       ` Michal Kubecek
2022-12-08  1:11 ` [PATCH ethtool v2 08/13] ethtool: fix runtime errors found by sanitizers Jesse Brandeburg
2022-12-08  6:34   ` Michal Kubecek
2022-12-09 17:42     ` Jesse Brandeburg
2022-12-09 18:09       ` Michal Kubecek
2022-12-09 22:09         ` Jesse Brandeburg
2022-12-08  1:11 ` [PATCH ethtool v2 09/13] ethtool: merge uapi changes to implement BIT and friends Jesse Brandeburg
2022-12-08  6:44   ` Michal Kubecek
2022-12-09 17:53     ` Jesse Brandeburg
2022-12-08  1:11 ` [PATCH ethtool v2 10/13] ethtool: refactor bit shifts to use BIT and BIT_ULL Jesse Brandeburg
2022-12-08  1:11 ` [PATCH ethtool v2 11/13] ethtool: fix missing free of memory after failure Jesse Brandeburg
2022-12-08 10:52   ` Michal Kubecek
2022-12-08  1:11 ` [PATCH ethtool v2 12/13] ethtool: fix leak of memory after realloc Jesse Brandeburg
2022-12-08 11:30   ` Michal Kubecek
2022-12-08  1:11 ` [PATCH ethtool v2 13/13] ethtool: fix bug and use standard string parsing Jesse Brandeburg
2022-12-08 11:48   ` Michal Kubecek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221208011122.2343363-5-jesse.brandeburg@intel.com \
    --to=jesse.brandeburg@intel.com \
    --cc=mkubecek@suse.cz \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.