From: Emil Velikov Date: Sun, 26 Jul 2026 16:47:28 +0000 (+0100) Subject: modinfo: add a couple of print_{all,parm} booleans X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0900f293634d22829cca2efcd6e930aa4969a5b9;p=thirdparty%2Fkmod.git modinfo: add a couple of print_{all,parm} booleans 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 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 12ae65e4..5091aa32 100644 --- a/tools/modinfo.c +++ b/tools/modinfo.c @@ -179,6 +179,8 @@ static int modinfo_do(struct kmod_module *mod) const enum kmod_module_initstate state = kmod_module_get_initstate(mod); const bool is_builtin = state == KMOD_MODULE_BUILTIN; const char *filename = is_builtin ? "(builtin)" : kmod_module_get_path(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; @@ -186,7 +188,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) { const char *name = kmod_module_get_name(mod); - if (field == NULL) + if (print_all) print_line("name", name); else if (streq(field, "name")) { print_line(NULL, name); @@ -194,7 +196,7 @@ static int modinfo_do(struct kmod_module *mod) } } - 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); goto end; @@ -244,7 +246,7 @@ static int modinfo_do(struct kmod_module *mod) } } - if (field != NULL) + if (!print_all) goto end; while (params != NULL) {