From: Emil Velikov Date: Sat, 18 Jul 2026 22:35:50 +0000 (+0100) Subject: modinfo: return early when --field is provided X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=838420308994ff4b2a7d9bd52a1e755d41de6756;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 92df6802..12ae65e4 100644 --- a/tools/modinfo.c +++ b/tools/modinfo.c @@ -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, ¶ms); if (err < 0) goto end;