From: Emil Velikov Date: Wed, 9 Oct 2024 15:26:25 +0000 (+0100) Subject: tools/rmmod: rework control flow X-Git-Tag: v34~243 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=70afc749bc7ad9a89fc2427eba5c3f26f1a4e0e9;p=thirdparty%2Fkmod.git tools/rmmod: rework control flow 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 Link: https://github.com/kmod-project/kmod/pull/180 Signed-off-by: Lucas De Marchi --- diff --git a/tools/rmmod.c b/tools/rmmod.c index ed985a8c..5dd7aa3a 100644 --- a/tools/rmmod.c +++ b/tools/rmmod.c @@ -96,7 +96,7 @@ static int do_rmmod(int argc, char *argv[]) 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; @@ -148,6 +148,8 @@ static int do_rmmod(int argc, char *argv[]) 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 @@ -160,16 +162,17 @@ static int do_rmmod(int argc, char *argv[]) } 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); }