Currently the control flow we use is a bit tricky:
- we use a goto within a loop, to avoid one function call
- we increment r, assuming it cannot wrap around
In practise these are not bugs, although make the code more convoluted
than needed. While in here, scope the local err to where it's used.
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/180
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
int verbose = LOG_ERR;
int use_syslog = 0;
int flags = 0;
- int i, err, r = 0;
+ int i, r = 0;
for (;;) {
int c, idx = 0;
struct kmod_module *mod;
const char *arg = argv[i];
struct stat st;
+ int err;
+
if (stat(arg, &st) == 0)
err = kmod_module_new_from_path(ctx, arg, &mod);
else
}
if (!(flags & KMOD_REMOVE_FORCE) && check_module_inuse(mod) < 0) {
- r++;
- goto next;
+ r = EXIT_FAILURE;
+ kmod_module_unref(mod);
+ continue;
}
err = kmod_module_remove_module(mod, flags);
if (err < 0) {
ERR("could not remove module %s: %s\n", arg, strerror(-err));
- r++;
+ r = EXIT_FAILURE;
}
-next:
+
kmod_module_unref(mod);
}