]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
modinfo: add a couple of print_{all,parm} booleans
authorEmil Velikov <emil.l.velikov@gmail.com>
Sun, 2 Aug 2026 12:26:13 +0000 (13:26 +0100)
committerLucas De Marchi <demarchi@kernel.org>
Mon, 10 Aug 2026 13:49:47 +0000 (08:49 -0500)
Add a couple of booleans to arguably make the code a wee-bit cleaner
to follow. A follow-up commit will further reuse the latter (print_parm)
to avoid repeatedly calling streq().

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/451
Signed-off-by: Lucas De Marchi <demarchi@kernel.org>
tools/modinfo.c

index 2393f860fe1337c15a4abd73551eaf783307ed44..2427747f43fd760931ee27c802567870aa925c5d 100644 (file)
@@ -176,6 +176,8 @@ end:
 
 static int modinfo_do(struct kmod_module *mod)
 {
+       const bool print_all = field == NULL;
+       const bool print_parm = !print_all && streq(field, "parm");
        struct kmod_list *l, *list = NULL;
        struct param *params = NULL;
        int err, is_builtin;
@@ -185,7 +187,7 @@ static int modinfo_do(struct kmod_module *mod)
 
        /* TODO: align builtin vs not wrt listing "name:" via kmod_module_get_info() */
        if (is_builtin) {
-               if (field == NULL)
+               if (print_all)
                        print_line("name", kmod_module_get_name(mod));
                else if (streq(field, "name")) {
                        print_line(NULL, kmod_module_get_name(mod));
@@ -194,7 +196,7 @@ static int modinfo_do(struct kmod_module *mod)
                filename = "(builtin)";
        }
 
-       if (field == NULL)
+       if (print_all)
                print_line("filename", filename);
        else if (streq(field, "filename")) {
                print_line(NULL, filename);
@@ -215,7 +217,7 @@ static int modinfo_do(struct kmod_module *mod)
                return err;
        }
 
-       if (field != NULL && streq(field, "parm")) {
+       if (print_parm) {
                err = modinfo_params_do(list);
                goto end;
        }
@@ -224,7 +226,7 @@ static int modinfo_do(struct kmod_module *mod)
                const char *key = kmod_module_info_get_key(l);
                const char *value = kmod_module_info_get_value(l);
 
-               if (field != NULL) {
+               if (!print_all) {
                        if (streq(field, key))
                                print_line(NULL, value);
                        continue;
@@ -242,7 +244,7 @@ static int modinfo_do(struct kmod_module *mod)
                }
        }
 
-       if (field != NULL)
+       if (!print_all)
                goto end;
 
        while (params != NULL) {