Skip to content

Commit ad2e2a7

Browse files
Sasha Levinmartinetd
authored andcommitted
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>
1 parent 34ceb69 commit ad2e2a7

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

net/9p/error.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <linux/list.h>
1717
#include <linux/jhash.h>
1818
#include <linux/errno.h>
19+
#include <linux/hashtable.h>
1920
#include <net/9p/9p.h>
2021

2122
/**
@@ -33,8 +34,8 @@ struct errormap {
3334
struct hlist_node list;
3435
};
3536

36-
#define ERRHASHSZ 32
37-
static struct hlist_head hash_errmap[ERRHASHSZ];
37+
#define ERRHASH_BITS 5
38+
static DEFINE_HASHTABLE(hash_errmap, ERRHASH_BITS);
3839

3940
/* FixMe - reduce to a reasonable size */
4041
static struct errormap errmap[] = {
@@ -176,18 +177,14 @@ static struct errormap errmap[] = {
176177
int p9_error_init(void)
177178
{
178179
struct errormap *c;
179-
int bucket;
180-
181-
/* initialize hash table */
182-
for (bucket = 0; bucket < ERRHASHSZ; bucket++)
183-
INIT_HLIST_HEAD(&hash_errmap[bucket]);
180+
u32 hash;
184181

185182
/* load initial error map into hash table */
186183
for (c = errmap; c->name; c++) {
187184
c->namelen = strlen(c->name);
188-
bucket = jhash(c->name, c->namelen, 0) % ERRHASHSZ;
185+
hash = jhash(c->name, c->namelen, 0);
189186
INIT_HLIST_NODE(&c->list);
190-
hlist_add_head(&c->list, &hash_errmap[bucket]);
187+
hash_add(hash_errmap, &c->list, hash);
191188
}
192189

193190
return 1;
@@ -205,12 +202,12 @@ int p9_errstr2errno(char *errstr, int len)
205202
{
206203
int errno;
207204
struct errormap *c;
208-
int bucket;
205+
u32 hash;
209206

210207
errno = 0;
211208
c = NULL;
212-
bucket = jhash(errstr, len, 0) % ERRHASHSZ;
213-
hlist_for_each_entry(c, &hash_errmap[bucket], list) {
209+
hash = jhash(errstr, len, 0);
210+
hash_for_each_possible(hash_errmap, c, list, hash) {
214211
if (c->namelen == len && !memcmp(c->name, errstr, len)) {
215212
errno = c->val;
216213
break;

0 commit comments

Comments
 (0)