Skip to content

Commit f18379a

Browse files
committed
modpost: split new_symbol() to symbol allocation and hash table addition
new_symbol() does two things; allocate a new symbol and register it to the hash table. Using a separate function for each is easier to understand. Replace new_symbol() with hash_add_symbol(). Remove the second parameter of alloc_symbol(). Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
1 parent e76cc48 commit f18379a

1 file changed

Lines changed: 8 additions & 10 deletions

File tree

scripts/mod/modpost.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -242,34 +242,31 @@ static inline unsigned int tdb_hash(const char *name)
242242
* Allocate a new symbols for use in the hash of exported symbols or
243243
* the list of unresolved symbols per module
244244
**/
245-
static struct symbol *alloc_symbol(const char *name, struct symbol *next)
245+
static struct symbol *alloc_symbol(const char *name)
246246
{
247247
struct symbol *s = NOFAIL(malloc(sizeof(*s) + strlen(name) + 1));
248248

249249
memset(s, 0, sizeof(*s));
250250
strcpy(s->name, name);
251-
s->next = next;
252251
s->is_static = true;
253252
return s;
254253
}
255254

256255
/* For the hash of exported symbols */
257-
static struct symbol *new_symbol(const char *name, struct module *module,
258-
enum export export)
256+
static void hash_add_symbol(struct symbol *sym)
259257
{
260258
unsigned int hash;
261259

262-
hash = tdb_hash(name) % SYMBOL_HASH_SIZE;
263-
symbolhash[hash] = alloc_symbol(name, symbolhash[hash]);
264-
265-
return symbolhash[hash];
260+
hash = tdb_hash(sym->name) % SYMBOL_HASH_SIZE;
261+
sym->next = symbolhash[hash];
262+
symbolhash[hash] = sym;
266263
}
267264

268265
static void sym_add_unresolved(const char *name, struct module *mod, bool weak)
269266
{
270267
struct symbol *sym;
271268

272-
sym = alloc_symbol(name, NULL);
269+
sym = alloc_symbol(name);
273270
sym->weak = weak;
274271

275272
list_add_tail(&sym->list, &mod->unresolved_symbols);
@@ -418,10 +415,11 @@ static struct symbol *sym_add_exported(const char *name, struct module *mod,
418415
s->module->is_vmlinux ? "" : ".ko");
419416
}
420417

421-
s = new_symbol(name, mod, export);
418+
s = alloc_symbol(name);
422419
s->module = mod;
423420
s->export = export;
424421
list_add_tail(&s->list, &mod->exported_symbols);
422+
hash_add_symbol(s);
425423

426424
return s;
427425
}

0 commit comments

Comments
 (0)