OSDN Git Service

modpost: strip .o from modname before calling new_module()
authorMasahiro Yamada <masahiroy@kernel.org>
Mon, 1 Jun 2020 05:57:29 +0000 (14:57 +0900)
committerMasahiro Yamada <masahiroy@kernel.org>
Sat, 6 Jun 2020 14:39:20 +0000 (23:39 +0900)
new_module() conditionally strips the .o because the modname has .o
suffix when it is called from read_symbols(), but no .o when it is
called from read_dump().

It is clearer to strip .o in read_symbols().

I also used flexible-array for mod->name.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
scripts/mod/modpost.c
scripts/mod/modpost.h

index b317328..ebfa9b7 100644 (file)
@@ -175,18 +175,12 @@ static struct module *find_module(const char *modname)
 static struct module *new_module(const char *modname)
 {
        struct module *mod;
-       char *p;
 
-       mod = NOFAIL(malloc(sizeof(*mod)));
+       mod = NOFAIL(malloc(sizeof(*mod) + strlen(modname) + 1));
        memset(mod, 0, sizeof(*mod));
-       p = NOFAIL(strdup(modname));
-
-       /* strip trailing .o */
-       if (strends(p, ".o"))
-               p[strlen(p) - 2] = '\0';
 
        /* add to list */
-       mod->name = p;
+       strcpy(mod->name, modname);
        mod->is_vmlinux = is_vmlinux(modname);
        mod->gpl_compatible = -1;
        mod->next = modules;
@@ -2013,7 +2007,15 @@ static void read_symbols(const char *modname)
        if (!parse_elf(&info, modname))
                return;
 
-       mod = new_module(modname);
+       {
+               char *tmp;
+
+               /* strip trailing .o */
+               tmp = NOFAIL(strdup(modname));
+               tmp[strlen(tmp) - 2] = '\0';
+               mod = new_module(tmp);
+               free(tmp);
+       }
 
        if (!mod->is_vmlinux) {
                license = get_modinfo(&info, "license");
index 3dc9e8f..254c753 100644 (file)
@@ -116,7 +116,6 @@ struct namespace_list {
 
 struct module {
        struct module *next;
-       const char *name;
        int gpl_compatible;
        struct symbol *unres;
        int from_dump;  /* 1 if module was loaded from *.symvers */
@@ -130,6 +129,7 @@ struct module {
        struct namespace_list *missing_namespaces;
        // Actual imported namespaces
        struct namespace_list *imported_namespaces;
+       char name[];
 };
 
 struct elf_info {