return 0;
 }
 
+/* Module within temporary copy, this doesn't do any allocation  */
+static int early_mod_check(struct load_info *info, int flags)
+{
+       int err;
+
+       /*
+        * Now that we know we have the correct module name, check
+        * if it's blacklisted.
+        */
+       if (blacklisted(info->name)) {
+               pr_err("Module %s is blacklisted\n", info->name);
+               return -EPERM;
+       }
+
+       err = rewrite_section_headers(info, flags);
+       if (err)
+               return err;
+
+       /* Check module struct version now, before we try to use module. */
+       if (!check_modstruct_version(info, info->mod))
+               return -ENOEXEC;
+
+       return 0;
+}
+
 /*
  * Allocate and load the module: note that size of section 0 is always
  * zero, and we rely on this for optional sections.
        if (err)
                goto free_copy;
 
-       /*
-        * Now that we know we have the correct module name, check
-        * if it's blacklisted.
-        */
-       if (blacklisted(info->name)) {
-               err = -EPERM;
-               pr_err("Module %s is blacklisted\n", info->name);
-               goto free_copy;
-       }
-
-       err = rewrite_section_headers(info, flags);
+       err = early_mod_check(info, flags);
        if (err)
                goto free_copy;
 
-       /* Check module struct version now, before we try to use module. */
-       if (!check_modstruct_version(info, info->mod)) {
-               err = -ENOEXEC;
-               goto free_copy;
-       }
-
        /* Figure out module layout, and allocate all the memory. */
        mod = layout_and_allocate(info, flags);
        if (IS_ERR(mod)) {