Skip to content

Commit 3554a45

Browse files
committed
modpost: use generic macros for hash table implementation
Use macros provided by hashtable.h Signed-off-by: Masahiro Yamada <[email protected]>
1 parent fbaf242 commit 3554a45

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

scripts/mod/modpost.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <stdbool.h>
2222
#include <errno.h>
2323

24+
#include <hashtable.h>
2425
#include <list.h>
2526
#include "modpost.h"
2627
#include "../../include/linux/license.h"
@@ -201,13 +202,8 @@ static struct module *new_module(const char *name, size_t namelen)
201202
return mod;
202203
}
203204

204-
/* A hash of all exported symbols,
205-
* struct symbol is also used for lists of unresolved symbols */
206-
207-
#define SYMBOL_HASH_SIZE 1024
208-
209205
struct symbol {
210-
struct symbol *next;
206+
struct hlist_node hnode;/* link to hash table */
211207
struct list_head list; /* link to module::exported_symbols or module::unresolved_symbols */
212208
struct module *module;
213209
char *namespace;
@@ -220,7 +216,7 @@ struct symbol {
220216
char name[];
221217
};
222218

223-
static struct symbol *symbolhash[SYMBOL_HASH_SIZE];
219+
static HASHTABLE_DEFINE(symbol_hashtable, 1U << 10);
224220

225221
/* This is based on the hash algorithm from gdbm, via tdb */
226222
static inline unsigned int tdb_hash(const char *name)
@@ -252,11 +248,7 @@ static struct symbol *alloc_symbol(const char *name)
252248
/* For the hash of exported symbols */
253249
static void hash_add_symbol(struct symbol *sym)
254250
{
255-
unsigned int hash;
256-
257-
hash = tdb_hash(sym->name) % SYMBOL_HASH_SIZE;
258-
sym->next = symbolhash[hash];
259-
symbolhash[hash] = sym;
251+
hash_add(symbol_hashtable, &sym->hnode, tdb_hash(sym->name));
260252
}
261253

262254
static void sym_add_unresolved(const char *name, struct module *mod, bool weak)
@@ -277,7 +269,7 @@ static struct symbol *sym_find_with_module(const char *name, struct module *mod)
277269
if (name[0] == '.')
278270
name++;
279271

280-
for (s = symbolhash[tdb_hash(name) % SYMBOL_HASH_SIZE]; s; s = s->next) {
272+
hash_for_each_possible(symbol_hashtable, s, hnode, tdb_hash(name)) {
281273
if (strcmp(s->name, name) == 0 && (!mod || s->module == mod))
282274
return s;
283275
}

0 commit comments

Comments
 (0)