Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

9p: Use hashtable.h for hash_errmap

Convert hash_errmap in error.c to use the generic hashtable
implementation from hashtable.h instead of the manual hlist_head array
implementation.

This simplifies the code and makes it more maintainable by using the
standard hashtable API and removes the need for manual hash table
management.

Signed-off-by: Sasha Levin <sashal@kernel.org>
Message-ID: <20250320145200.3124863-1-sashal@kernel.org>
Signed-off-by: Dominique Martinet <asmadeus@codewreck.org>

authored by

Sasha Levin and committed by
Dominique Martinet
ad2e2a77 34ceb69e

+9 -12
+9 -12
net/9p/error.c
··· 16 16 #include <linux/list.h> 17 17 #include <linux/jhash.h> 18 18 #include <linux/errno.h> 19 + #include <linux/hashtable.h> 19 20 #include <net/9p/9p.h> 20 21 21 22 /** ··· 34 33 struct hlist_node list; 35 34 }; 36 35 37 - #define ERRHASHSZ 32 38 - static struct hlist_head hash_errmap[ERRHASHSZ]; 36 + #define ERRHASH_BITS 5 37 + static DEFINE_HASHTABLE(hash_errmap, ERRHASH_BITS); 39 38 40 39 /* FixMe - reduce to a reasonable size */ 41 40 static struct errormap errmap[] = { ··· 177 176 int p9_error_init(void) 178 177 { 179 178 struct errormap *c; 180 - int bucket; 181 - 182 - /* initialize hash table */ 183 - for (bucket = 0; bucket < ERRHASHSZ; bucket++) 184 - INIT_HLIST_HEAD(&hash_errmap[bucket]); 179 + u32 hash; 185 180 186 181 /* load initial error map into hash table */ 187 182 for (c = errmap; c->name; c++) { 188 183 c->namelen = strlen(c->name); 189 - bucket = jhash(c->name, c->namelen, 0) % ERRHASHSZ; 184 + hash = jhash(c->name, c->namelen, 0); 190 185 INIT_HLIST_NODE(&c->list); 191 - hlist_add_head(&c->list, &hash_errmap[bucket]); 186 + hash_add(hash_errmap, &c->list, hash); 192 187 } 193 188 194 189 return 1; ··· 202 205 { 203 206 int errno; 204 207 struct errormap *c; 205 - int bucket; 208 + u32 hash; 206 209 207 210 errno = 0; 208 211 c = NULL; 209 - bucket = jhash(errstr, len, 0) % ERRHASHSZ; 210 - hlist_for_each_entry(c, &hash_errmap[bucket], list) { 212 + hash = jhash(errstr, len, 0); 213 + hash_for_each_possible(hash_errmap, c, list, hash) { 211 214 if (c->namelen == len && !memcmp(c->name, errstr, len)) { 212 215 errno = c->val; 213 216 break;