@@ -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);
}
}
@@ -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);
}
@@ -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,
@@ -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]);
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(-)