Close and delete JSON object only after output of SFP diagnostics so that it is also JSON formatted. If the JSON object is deleted too early, some of the output will not be JSON formatted, resulting in mixed output formats. Fixes: 703bfee13649 (ethtool: Enable JSON output support for SFF8079 and SFF8472 modules) Signed-off-by: Johannes Eigner --- sfpid.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sfpid.c b/sfpid.c index 62acb4f..9d09256 100644 --- a/sfpid.c +++ b/sfpid.c @@ -520,22 +520,23 @@ int sff8079_show_all_nl(struct cmd_context *ctx) new_json_obj(ctx->json); open_json_object(NULL); sff8079_show_all_common(buf); - close_json_object(); - delete_json_obj(); /* Finish if A2h page is not present */ if (!(buf[92] & (1 << 6))) - goto out; + goto out_json; /* Read A2h page */ ret = sff8079_get_eeprom_page(ctx, SFF8079_I2C_ADDRESS_HIGH, buf + ETH_MODULE_SFF_8079_LEN); if (ret) { fprintf(stderr, "Failed to read Page A2h.\n"); - goto out; + goto out_json; } sff8472_show_all(buf); +out_json: + close_json_object(); + delete_json_obj(); out: free(buf); -- 2.43.0 Append "_thresholds" to the threshold JSON objects to avoid using the same key which is not allowed in JSON. The JSON output for SFP transceivers uses the keys "laser_bias_current", "laser_output_power", "module_temperature" and "module_voltage" for both the actual value and the threshold values. This leads to invalid JSON output as keys in a JSON object must be unique. For QSPI and CMIS the keys "module_temperature" and "module_voltage" are also used for both the actual value and the threshold values. Fixes: 3448a2f73e77 (cmis: Add JSON output handling to --module-info in CMIS modules) Fixes: 008167804e54 (module_common: Add helpers to support JSON printing for common value types) Signed-off-by: Johannes Eigner --- sff-common.c | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/sff-common.c b/sff-common.c index 0824dfb..6528f5a 100644 --- a/sff-common.c +++ b/sff-common.c @@ -104,39 +104,39 @@ void sff8024_show_encoding(const __u8 *id, int encoding_offset, int sff_type) void sff_show_thresholds_json(struct sff_diags sd) { - open_json_object("laser_bias_current"); - PRINT_BIAS_JSON("high_alarm_threshold", sd.bias_cur[HALRM]); - PRINT_BIAS_JSON("low_alarm_threshold", sd.bias_cur[LALRM]); - PRINT_BIAS_JSON("high_warning_threshold", sd.bias_cur[HWARN]); - PRINT_BIAS_JSON("low_warning_threshold", sd.bias_cur[LWARN]); + open_json_object("laser_bias_current_thresholds"); + PRINT_BIAS_JSON("high_alarm", sd.bias_cur[HALRM]); + PRINT_BIAS_JSON("low_alarm", sd.bias_cur[LALRM]); + PRINT_BIAS_JSON("high_warning", sd.bias_cur[HWARN]); + PRINT_BIAS_JSON("low_warning", sd.bias_cur[LWARN]); close_json_object(); - open_json_object("laser_output_power"); - PRINT_xX_PWR_JSON("high_alarm_threshold", sd.tx_power[HALRM]); - PRINT_xX_PWR_JSON("low_alarm_threshold", sd.tx_power[LALRM]); - PRINT_xX_PWR_JSON("high_warning_threshold", sd.tx_power[HWARN]); - PRINT_xX_PWR_JSON("low_warning_threshold", sd.tx_power[LWARN]); + open_json_object("laser_output_power_thresholds"); + PRINT_xX_PWR_JSON("high_alarm", sd.tx_power[HALRM]); + PRINT_xX_PWR_JSON("low_alarm", sd.tx_power[LALRM]); + PRINT_xX_PWR_JSON("high_warning", sd.tx_power[HWARN]); + PRINT_xX_PWR_JSON("low_warning", sd.tx_power[LWARN]); close_json_object(); - open_json_object("module_temperature"); - PRINT_TEMP_JSON("high_alarm_threshold", sd.sfp_temp[HALRM]); - PRINT_TEMP_JSON("low_alarm_threshold", sd.sfp_temp[LALRM]); - PRINT_TEMP_JSON("high_warning_threshold", sd.sfp_temp[HWARN]); - PRINT_TEMP_JSON("low_warning_threshold", sd.sfp_temp[LWARN]); + open_json_object("module_temperature_thresholds"); + PRINT_TEMP_JSON("high_alarm", sd.sfp_temp[HALRM]); + PRINT_TEMP_JSON("low_alarm", sd.sfp_temp[LALRM]); + PRINT_TEMP_JSON("high_warning", sd.sfp_temp[HWARN]); + PRINT_TEMP_JSON("low_warning", sd.sfp_temp[LWARN]); close_json_object(); - open_json_object("module_voltage"); - PRINT_VCC_JSON("high_alarm_threshold", sd.sfp_voltage[HALRM]); - PRINT_VCC_JSON("low_alarm_threshold", sd.sfp_voltage[LALRM]); - PRINT_VCC_JSON("high_warning_threshold", sd.sfp_voltage[HWARN]); - PRINT_VCC_JSON("low_warning_threshold", sd.sfp_voltage[LWARN]); + open_json_object("module_voltage_thresholds"); + PRINT_VCC_JSON("high_alarm", sd.sfp_voltage[HALRM]); + PRINT_VCC_JSON("low_alarm", sd.sfp_voltage[LALRM]); + PRINT_VCC_JSON("high_warning", sd.sfp_voltage[HWARN]); + PRINT_VCC_JSON("low_warning", sd.sfp_voltage[LWARN]); close_json_object(); - open_json_object("laser_rx_power"); - PRINT_xX_PWR_JSON("high_alarm_threshold", sd.rx_power[HALRM]); - PRINT_xX_PWR_JSON("low_alarm_threshold", sd.rx_power[LALRM]); - PRINT_xX_PWR_JSON("high_warning_threshold", sd.rx_power[HWARN]); - PRINT_xX_PWR_JSON("low_warning_threshold", sd.rx_power[LWARN]); + open_json_object("laser_rx_power_thresholds"); + PRINT_xX_PWR_JSON("high_alarm", sd.rx_power[HALRM]); + PRINT_xX_PWR_JSON("low_alarm", sd.rx_power[LALRM]); + PRINT_xX_PWR_JSON("high_warning", sd.rx_power[HWARN]); + PRINT_xX_PWR_JSON("low_warning", sd.rx_power[LWARN]); close_json_object(); } -- 2.43.0