Re: [PATCH 1/5] scripts: add bit count parameter back to host hash functions
From: Linus Torvalds
Date: Thu Nov 26 2026 - 20:34:35 EST
On Thu, 26 Nov 2026 at 17:16, Linus Torvalds
<torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:
>
> NOTE NOTE NOTE! This is untested crap. It shows the *concept*. It
> might even work. But it might also do unspeakable things to your pets.
> Don't trust my word for it. Look at the code and test it.
Some more testing shows that it needs at least something like this on
top..
With this it *might* actually work. But when I say "some more testing",
that "some" is still carrying a lot of weight. Not a lot of, IOW.
I did say it was untested crap. I guess I'm more of a "high-level
concepts guy" than detail-oriented.
Users? I like to call them "Test subjects" or "Victims".
Linus
---
diff --git a/scripts/include/hashtable.h b/scripts/include/hashtable.h
index 0d8bb8eb178c..78d63eb96fc4 100644
--- a/scripts/include/hashtable.h
+++ b/scripts/include/hashtable.h
@@ -12,10 +12,14 @@
} name
#define HASHTABLE_DEFINE(name, bits) \
- HASHTABLE_DECLARE(name, bits) = { { [0 ... ((1 << (bits)) - 1)] =
HLIST_HEAD_INIT } }
+ HASHTABLE_DECLARE(name, bits) = { { [0 ... ((1 << (bits)) - 1)] =
HLIST_HEAD_INIT } }
+
+/* Define a table already declared extern with HASHTABLE_DECLARE() */
+#define HASHTABLE_DEFINE_EXTERN(name) \
+ typeof(name) name = { { [0 ... HASH_SIZE(name) - 1] = HLIST_HEAD_INIT } }
#define HASH_BITS(name) (sizeof((name).hash_bits))
-#define HASH_SIZE(name) (1ul << HASH_BITS(name))
+#define HASH_SIZE(name) ARRAY_SIZE((name).hlist)
#define hash_head(table, key) (&(table).hlist[(unsigned)(key) >>
(32-HASH_BITS(table))])
@@ -31,7 +35,7 @@ static inline void __hash_init(struct hlist_head
*ht, unsigned int sz)
* hash_init - initialize a hash table
* @table: hashtable to be initialized
*/
-#define hash_init(table) __hash_init(table, HASH_SIZE(table))
+#define hash_init(table) __hash_init((table).hlist, HASH_SIZE(table))
/**
* hash_add - add an object to a hashtable
@@ -59,7 +63,7 @@ static inline void hash_del(struct hlist_node *node)
*/
#define hash_for_each(table, obj, member) \
for (int _bkt = 0; _bkt < HASH_SIZE(table); _bkt++) \
- hlist_for_each_entry(obj, &table[_bkt].hlist, member)
+ hlist_for_each_entry(obj, &(table).hlist[_bkt], member)
/**
* hash_for_each_safe - iterate over a hashtable safe against removal of
@@ -71,7 +75,7 @@ static inline void hash_del(struct hlist_node *node)
*/
#define hash_for_each_safe(table, obj, tmp, member) \
for (int _bkt = 0; _bkt < HASH_SIZE(table); _bkt++) \
- hlist_for_each_entry_safe(obj, tmp, &table[_bkt].hlist, member)
+ hlist_for_each_entry_safe(obj, tmp, &(table).hlist[_bkt], member)
/**
* hash_for_each_possible - iterate over all possible objects hashing to the
diff --git a/scripts/kconfig/expr.c b/scripts/kconfig/expr.c
index 27278830de98..26b0a64b5cb5 100644
--- a/scripts/kconfig/expr.c
+++ b/scripts/kconfig/expr.c
@@ -16,7 +16,7 @@
#define DEBUG_EXPR 0
-HASHTABLE_DEFINE(expr_hashtable, EXPR_HASH_BITS);
+HASHTABLE_DEFINE_EXTERN(expr_hashtable);
static struct expr *expr_eliminate_yn(struct expr *e);
diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c
index dec65c0d1181..2afe2be78a29 100644
--- a/scripts/kconfig/symbol.c
+++ b/scripts/kconfig/symbol.c
@@ -971,7 +971,7 @@ bool sym_is_choice_value(const struct symbol *sym)
return !list_empty(&sym->choice_link);
}
-HASHTABLE_DEFINE(sym_hashtable, SYMBOL_HASH_BITS);
+HASHTABLE_DEFINE_EXTERN(sym_hashtable);
struct symbol *sym_lookup(const char *name, int flags)
{