opticsmon: Handle error return of ethtool_nl_connect()

Don't just ignore the return of ethtool_nl_connect(). This would also
otherwise lead to invalid socket accesses later. Also make
ethtool_nl_connect() return negative error values instead of
EXIT_FAILURE.

Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
Niklas Schnelle
2026-04-16 14:40:47 +02:00
committed by Jan Höppner
parent 6847b6a8cf
commit 3696d6bd08
2 changed files with 6 additions and 4 deletions

View File

@@ -56,13 +56,13 @@ int ethtool_nl_connect(struct ethtool_nl_ctx *ctx)
sk = nl_socket_alloc();
if (!sk) {
nl_perror(NLE_NOMEM, "alloc");
return EXIT_FAILURE;
return -ENOMEM;
}
rc = genl_connect(sk);
if (rc) {
nl_perror(rc, "connect");
rc = EXIT_FAILURE;
rc = -EIO;
goto err_free;
}
@@ -72,7 +72,7 @@ int ethtool_nl_connect(struct ethtool_nl_ctx *ctx)
fprintf(stderr, "Ethtool netlink family not found\n");
else
nl_perror(ethtool_id, "ctrl resolve");
rc = EXIT_FAILURE;
rc = -EIO;
goto err_close;
}
ctx->sk = sk;

View File

@@ -398,7 +398,9 @@ int main(int argc, char **argv)
int ret;
parse_cmdline(argc, argv, &ctx.opts);
ethtool_nl_connect(&ctx.ethtool_ctx);
ret = ethtool_nl_connect(&ctx.ethtool_ctx);
if (ret)
return ret;
if (ctx.opts.monitor)
ret = monitor_mode(&ctx);
else