mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-04-13 09:59:31 +00:00
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>
This commit is contained in:
parent
34ceb69edd
commit
ad2e2a77dc
1 changed files with 9 additions and 12 deletions
|
@ -16,6 +16,7 @@
|
||||||
#include <linux/list.h>
|
#include <linux/list.h>
|
||||||
#include <linux/jhash.h>
|
#include <linux/jhash.h>
|
||||||
#include <linux/errno.h>
|
#include <linux/errno.h>
|
||||||
|
#include <linux/hashtable.h>
|
||||||
#include <net/9p/9p.h>
|
#include <net/9p/9p.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -33,8 +34,8 @@ struct errormap {
|
||||||
struct hlist_node list;
|
struct hlist_node list;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define ERRHASHSZ 32
|
#define ERRHASH_BITS 5
|
||||||
static struct hlist_head hash_errmap[ERRHASHSZ];
|
static DEFINE_HASHTABLE(hash_errmap, ERRHASH_BITS);
|
||||||
|
|
||||||
/* FixMe - reduce to a reasonable size */
|
/* FixMe - reduce to a reasonable size */
|
||||||
static struct errormap errmap[] = {
|
static struct errormap errmap[] = {
|
||||||
|
@ -176,18 +177,14 @@ static struct errormap errmap[] = {
|
||||||
int p9_error_init(void)
|
int p9_error_init(void)
|
||||||
{
|
{
|
||||||
struct errormap *c;
|
struct errormap *c;
|
||||||
int bucket;
|
u32 hash;
|
||||||
|
|
||||||
/* initialize hash table */
|
|
||||||
for (bucket = 0; bucket < ERRHASHSZ; bucket++)
|
|
||||||
INIT_HLIST_HEAD(&hash_errmap[bucket]);
|
|
||||||
|
|
||||||
/* load initial error map into hash table */
|
/* load initial error map into hash table */
|
||||||
for (c = errmap; c->name; c++) {
|
for (c = errmap; c->name; c++) {
|
||||||
c->namelen = strlen(c->name);
|
c->namelen = strlen(c->name);
|
||||||
bucket = jhash(c->name, c->namelen, 0) % ERRHASHSZ;
|
hash = jhash(c->name, c->namelen, 0);
|
||||||
INIT_HLIST_NODE(&c->list);
|
INIT_HLIST_NODE(&c->list);
|
||||||
hlist_add_head(&c->list, &hash_errmap[bucket]);
|
hash_add(hash_errmap, &c->list, hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -205,12 +202,12 @@ int p9_errstr2errno(char *errstr, int len)
|
||||||
{
|
{
|
||||||
int errno;
|
int errno;
|
||||||
struct errormap *c;
|
struct errormap *c;
|
||||||
int bucket;
|
u32 hash;
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
c = NULL;
|
c = NULL;
|
||||||
bucket = jhash(errstr, len, 0) % ERRHASHSZ;
|
hash = jhash(errstr, len, 0);
|
||||||
hlist_for_each_entry(c, &hash_errmap[bucket], list) {
|
hash_for_each_possible(hash_errmap, c, list, hash) {
|
||||||
if (c->namelen == len && !memcmp(c->name, errstr, len)) {
|
if (c->namelen == len && !memcmp(c->name, errstr, len)) {
|
||||||
errno = c->val;
|
errno = c->val;
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Add table
Reference in a new issue