]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
modinfo: return early when --field is provided
authorEmil Velikov <emil.l.velikov@gmail.com>
Sat, 18 Jul 2026 22:35:50 +0000 (23:35 +0100)
committerLucas De Marchi <demarchi@kernel.org>
Thu, 6 Aug 2026 01:35:44 +0000 (20:35 -0500)
No point in continuing if only a certain field is requested.

While in here, use a consistent code-pattern for the process.

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 92df68020ea54c992374851d25e48d1fb228f28e..12ae65e436462043756424677f2d8dca7853df4a 100644 (file)
@@ -188,15 +188,17 @@ static int modinfo_do(struct kmod_module *mod)
                const char *name = kmod_module_get_name(mod);
                if (field == NULL)
                        print_line("name", name);
-               else if (field != NULL && streq(field, "name"))
+               else if (streq(field, "name")) {
                        print_line(NULL, name);
+                       return 0;
+               }
        }
 
-       if (field != NULL && streq(field, "filename")) {
+       if (field == NULL)
+               print_line("filename", filename);
+       else if (streq(field, "filename")) {
                print_line(NULL, filename);
                return 0;
-       } else if (field == NULL) {
-               print_line("filename", filename);
        }
 
        err = kmod_module_get_info(mod, &list);
@@ -225,8 +227,11 @@ static int modinfo_do(struct kmod_module *mod)
                if (field != NULL) {
                        if (streq(field, key)) {
                                print_line(NULL, value);
+                               goto end;
                        }
-               } else if (streq(key, "parm")) {
+                       continue;
+               }
+               if (streq(key, "parm")) {
                        err = process_parm(parm_desc, value, &params);
                        if (err < 0)
                                goto end;