From 963faa0063e89bfd0d807b3c25fcb0723541a045 Mon Sep 17 00:00:00 2001 From: Ben Hutchings Date: Wed, 10 Oct 2012 22:19:15 +0100 Subject: Gracefully handle failure of register dump pretty-printer If we have a pretty-printer matching the driver name for a register dump, but it doesn't handle the reported dump version, then we currently fail and print: Cannot dump registers: Success Instead, fall back to hex dump. Also, don't use perror() to explain a failure of dump_regs(). errno is not meaningful in either failure case. Signed-off-by: Ben Hutchings --- ethtool.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/ethtool.c b/ethtool.c index f3649e2..1081576 100644 --- a/ethtool.c +++ b/ethtool.c @@ -934,8 +934,15 @@ static int dump_regs(int gregs_dump_raw, int gregs_dump_hex, if (!gregs_dump_hex) for (i = 0; i < ARRAY_SIZE(driver_list); i++) if (!strncmp(driver_list[i].name, info->driver, - ETHTOOL_BUSINFO_LEN)) - return driver_list[i].func(info, regs); + ETHTOOL_BUSINFO_LEN)) { + if (driver_list[i].func(info, regs) == 0) + return 0; + /* This version (or some other + * variation in the dump format) is + * not handled; fall back to hex + */ + break; + } dump_hex(stdout, regs->data, regs->len, 0); @@ -2632,7 +2639,7 @@ static int do_gregs(struct cmd_context *ctx) } if (dump_regs(gregs_dump_raw, gregs_dump_hex, gregs_dump_file, &drvinfo, regs) < 0) { - perror("Cannot dump registers"); + fprintf(stderr, "Cannot dump registers\n"); free(regs); return 75; } -- cgit v1.2.1