module: add a for_each_modinfo_entry()
authorLuis Chamberlain <mcgrof@kernel.org>
Sun, 19 Mar 2023 21:27:37 +0000 (14:27 -0700)
committerLuis Chamberlain <mcgrof@kernel.org>
Fri, 24 Mar 2023 18:05:15 +0000 (11:05 -0700)
Add a for_each_modinfo_entry() to make it easier to read and use.
This produces no functional changes but makes this code easiert
to read as we are used to with loops in the kernel and trims more
lines of code.

Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
kernel/module/internal.h
kernel/module/main.c

index 1fa2328636ec29bf906b77cfd45ae12ce9da1c04..6ae29bb8836f89d79cf1754c8aab8fad6e4378b4 100644 (file)
@@ -98,6 +98,9 @@ size_t module_flags_taint(unsigned long taints, char *buf);
 
 char *module_next_tag_pair(char *string, unsigned long *secsize);
 
+#define for_each_modinfo_entry(entry, info, name) \
+       for (entry = get_modinfo(info, name); entry; entry = get_next_modinfo(info, name, entry))
+
 static inline void module_assert_mutex_or_preempt(void)
 {
 #ifdef CONFIG_LOCKDEP
index ebb5e6b92a48f5440cc4a61afd4cb25402e44ecb..427284ab31f1de91195085c20f1c33831a715abf 100644 (file)
@@ -1075,12 +1075,9 @@ static int verify_namespace_is_imported(const struct load_info *info,
 
        namespace = kernel_symbol_namespace(sym);
        if (namespace && namespace[0]) {
-               imported_namespace = get_modinfo(info, "import_ns");
-               while (imported_namespace) {
+               for_each_modinfo_entry(imported_namespace, info, "import_ns") {
                        if (strcmp(namespace, imported_namespace) == 0)
                                return 0;
-                       imported_namespace = get_next_modinfo(
-                               info, "import_ns", imported_namespace);
                }
 #ifdef CONFIG_MODULE_ALLOW_MISSING_NAMESPACE_IMPORTS
                pr_warn(