Skip to content

Commit a82f794

Browse files
committed
modpost: strip .o from modname before calling new_module()
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>
1 parent 858b937 commit a82f794

2 files changed

Lines changed: 12 additions & 10 deletions

File tree

‎scripts/mod/modpost.c‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,18 +175,12 @@ static struct module *find_module(const char *modname)
175175
static struct module *new_module(const char *modname)
176176
{
177177
struct module *mod;
178-
char *p;
179178

180-
mod = NOFAIL(malloc(sizeof(*mod)));
179+
mod = NOFAIL(malloc(sizeof(*mod) + strlen(modname) + 1));
181180
memset(mod, 0, sizeof(*mod));
182-
p = NOFAIL(strdup(modname));
183-
184-
/* strip trailing .o */
185-
if (strends(p, ".o"))
186-
p[strlen(p) - 2] = '\0';
187181

188182
/* add to list */
189-
mod->name = p;
183+
strcpy(mod->name, modname);
190184
mod->is_vmlinux = is_vmlinux(modname);
191185
mod->gpl_compatible = -1;
192186
mod->next = modules;
@@ -2013,7 +2007,15 @@ static void read_symbols(const char *modname)
20132007
if (!parse_elf(&info, modname))
20142008
return;
20152009

2016-
mod = new_module(modname);
2010+
{
2011+
char *tmp;
2012+
2013+
/* strip trailing .o */
2014+
tmp = NOFAIL(strdup(modname));
2015+
tmp[strlen(tmp) - 2] = '\0';
2016+
mod = new_module(tmp);
2017+
free(tmp);
2018+
}
20172019

20182020
if (!mod->is_vmlinux) {
20192021
license = get_modinfo(&info, "license");

‎scripts/mod/modpost.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ struct namespace_list {
116116

117117
struct module {
118118
struct module *next;
119-
const char *name;
120119
int gpl_compatible;
121120
struct symbol *unres;
122121
int from_dump; /* 1 if module was loaded from *.symvers */
@@ -130,6 +129,7 @@ struct module {
130129
struct namespace_list *missing_namespaces;
131130
// Actual imported namespaces
132131
struct namespace_list *imported_namespaces;
132+
char name[];
133133
};
134134

135135
struct elf_info {

0 commit comments

Comments
 (0)