From: Emil Velikov Date: Wed, 7 May 2025 12:10:42 +0000 (+0100) Subject: libkmod: fixup kmod_module_get_initstate() error reporting X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=428ed42cf4e602fb49a7f83bff757c3cc65663bb;p=thirdparty%2Fkmod.git libkmod: fixup kmod_module_get_initstate() error reporting Currently, the function will report the exact same issue twice. Where the second DBG() and the error code returned, should highlight the (potential) stat(2) failure. Signed-off-by: Emil Velikov Link: https://github.com/kmod-project/kmod/pull/346 Signed-off-by: Lucas De Marchi --- diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c index 2b51010e..a9d103e6 100644 --- a/libkmod/libkmod-module.c +++ b/libkmod/libkmod-module.c @@ -1434,7 +1434,6 @@ KMOD_EXPORT int kmod_module_get_initstate(const struct kmod_module *mod) fd = open(path, O_RDONLY | O_CLOEXEC); if (fd < 0) { err = -errno; - DBG(mod->ctx, "could not open '%s': %s\n", path, strerror(-err)); if (pathlen > (int)sizeof("/initstate") - 1) { @@ -1442,9 +1441,10 @@ KMOD_EXPORT int kmod_module_get_initstate(const struct kmod_module *mod) path[pathlen - (sizeof("/initstate") - 1)] = '\0'; if (stat(path, &st) == 0 && S_ISDIR(st.st_mode)) return KMOD_MODULE_COMING; - } - DBG(mod->ctx, "could not open '%s': %s\n", path, strerror(-err)); + err = -errno; + DBG(mod->ctx, "could not open '%s': %s\n", path, strerror(-err)); + } return err; }