From 3696d6bd0858006bace1819c3ba436491f750c7b Mon Sep 17 00:00:00 2001 From: Niklas Schnelle Date: Thu, 16 Apr 2026 14:40:47 +0200 Subject: [PATCH] opticsmon: Handle error return of ethtool_nl_connect() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Niklas Schnelle Signed-off-by: Jan Höppner --- opticsmon/ethtool.c | 6 +++--- opticsmon/opticsmon.c | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/opticsmon/ethtool.c b/opticsmon/ethtool.c index a448eb25..ac1a07fb 100644 --- a/opticsmon/ethtool.c +++ b/opticsmon/ethtool.c @@ -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; diff --git a/opticsmon/opticsmon.c b/opticsmon/opticsmon.c index 6d7595b1..c50275d4 100644 --- a/opticsmon/opticsmon.c +++ b/opticsmon/opticsmon.c @@ -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