]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
tools/insmod: use single control variable
authorEmil Velikov <emil.l.velikov@gmail.com>
Wed, 9 Oct 2024 15:26:25 +0000 (16:26 +0100)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Tue, 15 Oct 2024 18:37:02 +0000 (13:37 -0500)
Currently we're returning success, if any of the pre libkmod checks
fail. That's because err is our local variable, while r is the (exit)
resutlt. In practise we don't need the distinction, so just drop the
former.

Reported by clang.

Fixes: ca8f04e8 ("tools/insmod: add syslog and verbose options")
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/180
[ add blank lines, remove extra braces ]
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
tools/insmod.c

index 60b8c7c3e045ae1d22f14c3185b77debfdde8840..b3d01c6a1fcdde0782438ec6dca3f2fdd5004bd3 100644 (file)
@@ -66,7 +66,7 @@ static int do_insmod(int argc, char *argv[])
        size_t optslen = 0;
        int verbose = LOG_ERR;
        int use_syslog = 0;
-       int i, err = 0, r = 0;
+       int i, r = 0;
        const char *null_config = NULL;
        unsigned int flags = 0;
 
@@ -142,18 +142,16 @@ static int do_insmod(int argc, char *argv[])
 
        log_setup_kmod_log(ctx, verbose);
 
-       err = kmod_module_new_from_path(ctx, filename, &mod);
-       if (err < 0) {
-               ERR("could not load module %s: %s\n", filename, strerror(-err));
-               r++;
+       r = kmod_module_new_from_path(ctx, filename, &mod);
+       if (r < 0) {
+               ERR("could not load module %s: %s\n", filename, strerror(-r));
                goto end;
        }
 
-       err = kmod_module_insert_module(mod, flags, opts);
-       if (err < 0) {
-               ERR("could not insert module %s: %s\n", filename, mod_strerror(-err));
-               r++;
-       }
+       r = kmod_module_insert_module(mod, flags, opts);
+       if (r < 0)
+               ERR("could not insert module %s: %s\n", filename, mod_strerror(-r));
+
        kmod_module_unref(mod);
 
 end:
@@ -161,7 +159,7 @@ end:
        free(opts);
 
        log_close();
-       return err >= 0 ? EXIT_SUCCESS : EXIT_FAILURE;
+       return r == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
 
 const struct kmod_cmd kmod_cmd_compat_insmod = {