]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
modinfo: return early when --field is provided
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)
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 3984ba984ce01d80d9a46f9e2c219dc520464e1c..2393f860fe1337c15a4abd73551eaf783307ed44 100644 (file)
@@ -187,16 +187,18 @@ static int modinfo_do(struct kmod_module *mod)
        if (is_builtin) {
                if (field == NULL)
                        print_line("name", kmod_module_get_name(mod));
-               else if (field != NULL && streq(field, "name"))
+               else if (streq(field, "name")) {
                        print_line(NULL, kmod_module_get_name(mod));
+                       return 0;
+               }
                filename = "(builtin)";
        }
 
-       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);
@@ -223,10 +225,11 @@ static int modinfo_do(struct kmod_module *mod)
                const char *value = kmod_module_info_get_value(l);
 
                if (field != NULL) {
-                       if (streq(field, key)) {
+                       if (streq(field, key))
                                print_line(NULL, value);
-                       }
-               } else if (streq(key, "parm")) {
+                       continue;
+               }
+               if (streq(key, "parm")) {
                        err = process_parm(parm_desc, value, &params);
                        if (err < 0)
                                goto end;