Restructure sff8079_show_all_nl() to first retrieve all the necessary pages (A0h and optionally A2h) and then pretty-print them, matching the pattern already used in cmis_show_all_nl() and sff8636_show_all_nl(). This prepares for the next patch which extends the function with a hex dump mode. Note that if reading A2h fails, the function now returns an error without producing partial output, matching the behavior of the other parsers. Assisted-by: Claude:claude-sonnet-4.6 Reviewed-by: Ido Schimmel Signed-off-by: Danielle Ratson --- sfpid.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/sfpid.c b/sfpid.c index 228b3ee..f753917 100644 --- a/sfpid.c +++ b/sfpid.c @@ -500,6 +500,7 @@ static int sff8079_get_eeprom_page(struct cmd_context *ctx, u8 i2c_address, int sff8079_show_all_nl(struct cmd_context *ctx) { + bool a2h_present; u8 *buf; int ret; @@ -516,24 +517,26 @@ int sff8079_show_all_nl(struct cmd_context *ctx) if (ret) goto out; + /* Check if A2h page is present */ + a2h_present = buf[92] & (1 << 6); + + if (a2h_present) { + /* 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; + } + } + new_json_obj(ctx->json); open_json_object(NULL); sff8079_show_all_common(buf); - /* Finish if A2h page is not present */ - if (!(buf[92] & (1 << 6))) - 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_json; - } + if (a2h_present) + sff8472_show_all(buf); - sff8472_show_all(buf); -out_json: close_json_object(); delete_json_obj(); out: -- 2.51.0