]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
modinfo: flesh out and reuse print_line helper
authorEmil Velikov <emil.l.velikov@gmail.com>
Sat, 18 Jul 2026 22:11:46 +0000 (23:11 +0100)
committerLucas De Marchi <demarchi@kernel.org>
Thu, 6 Aug 2026 01:35:44 +0000 (20:35 -0500)
Thus using the correct format when `--null` is specified. In particular,
the both name + filename use the correct format, when --null (mode) is
requested.

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 3f013ecfe53378ad85f86a07d696ee45de11e366..92df68020ea54c992374851d25e48d1fb228f28e 100644 (file)
@@ -110,6 +110,23 @@ static int process_parm(enum parm_info parm_info, const char *value, struct para
        return 0;
 }
 
+static void print_line(const char *key, const char *value)
+{
+       if (key == NULL) {
+               printf("%s%c", value, separator);
+               return;
+       }
+
+       if (separator == '\0') {
+               printf("%s=%s%c", key, value, separator);
+       } else {
+               size_t keylen = strlen(key);
+               if (keylen > 15)
+                       keylen = 15;
+               printf("%s:%-*s%s%c", key, 15 - (int)keylen, "", value, separator);
+       }
+}
+
 static int modinfo_params_do(const struct kmod_list *list)
 {
        const struct kmod_list *l;
@@ -168,17 +185,18 @@ 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)
-                       printf("%-16s%s%c", "name:", kmod_module_get_name(mod), separator);
+                       print_line("name", name);
                else if (field != NULL && streq(field, "name"))
-                       printf("%s%c", kmod_module_get_name(mod), separator);
+                       print_line(NULL, name);
        }
 
        if (field != NULL && streq(field, "filename")) {
-               printf("%s%c", filename, separator);
+               print_line(NULL, filename);
                return 0;
        } else if (field == NULL) {
-               printf("%-16s%s%c", "filename:", filename, separator);
+               print_line("filename", filename);
        }
 
        err = kmod_module_get_info(mod, &list);
@@ -206,8 +224,7 @@ static int modinfo_do(struct kmod_module *mod)
 
                if (field != NULL) {
                        if (streq(field, key)) {
-                               /* filtered output contains no key, just value */
-                               printf("%s%c", value, separator);
+                               print_line(NULL, value);
                        }
                } else if (streq(key, "parm")) {
                        err = process_parm(parm_desc, value, &params);
@@ -217,13 +234,8 @@ static int modinfo_do(struct kmod_module *mod)
                        err = process_parm(parm_type, value, &params);
                        if (err < 0)
                                goto end;
-               } else if (separator == '\0') {
-                       printf("%s=%s%c", key, value, separator);
                } else {
-                       size_t keylen = strlen(key);
-                       if (keylen > 15)
-                               keylen = 15;
-                       printf("%s:%-*s%s%c", key, 15 - (int)keylen, "", value, separator);
+                       print_line(key, value);
                }
        }