From: Emil Velikov Date: Sun, 2 Aug 2026 12:26:13 +0000 (+0100) Subject: modinfo: return early when --field is provided X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9872e9a496ecbbf5fecd66697eaec450d3e6e513;p=thirdparty%2Fkmod.git modinfo: return early when --field is provided 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 Link: https://github.com/kmod-project/kmod/pull/451 Signed-off-by: Lucas De Marchi --- diff --git a/tools/modinfo.c b/tools/modinfo.c index 3984ba9..2393f86 100644 --- a/tools/modinfo.c +++ b/tools/modinfo.c @@ -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, ¶ms); if (err < 0) goto end;