diff mbox series

[1/4] modules: factor out arch check

Message ID 20210610101553.943689-2-kraxel@redhat.com (mailing list archive)
State New, archived
Headers show
Series modules: add support for target-specific modules. | expand

Commit Message

Gerd Hoffmann June 10, 2021, 10:15 a.m. UTC
Move check to helper function for easy reuse.
No functional change.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 util/module.c | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/util/module.c b/util/module.c
index 4f98cc74ae37..860c257fc56e 100644
--- a/util/module.c
+++ b/util/module.c
@@ -129,6 +129,21 @@  void module_allow_arch(const char *arch)
     module_arch = arch;
 }
 
+static bool module_check_arch(ModuleInfo *info)
+{
+    if (info->has_arch) {
+        if (!module_arch) {
+            /* no arch set -> ignore all */
+            return false;
+        }
+        if (strcmp(module_arch, info->arch) != 0) {
+            /* mismatch */
+            return false;
+        }
+    }
+    return true;
+}
+
 static void module_load_path_init(void)
 {
     const char *search_dir;
@@ -301,12 +316,9 @@  bool module_load_one(const char *prefix, const char *lib_name, bool mayfail)
     module_load_modinfo();
 
     for (modlist = modinfo->list; modlist != NULL; modlist = modlist->next) {
-        if (modlist->value->has_arch) {
-            if (strcmp(modlist->value->name, module_name) == 0) {
-                if (!module_arch ||
-                    strcmp(modlist->value->arch, module_arch) != 0) {
-                    return false;
-                }
+        if (strcmp(modlist->value->name, module_name) == 0) {
+            if (!module_check_arch(modlist->value)) {
+                return false;
             }
         }
         if (modlist->value->has_deps) {