diff options
author | Ivaylo Dimitrov <freemangordon@abv.bg> | 2014-01-06 03:17:27 +0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2014-01-09 22:36:59 +0400 |
commit | d30555853052bbec8497260ba888b7d696bed9b8 (patch) | |
tree | 9881511b47f531487c96ad68dd7405bc15f8be15 /drivers/staging/tidspbridge/pmgr | |
parent | 3a21f00a5002b14e4aab52aef59d33ed28468a13 (diff) | |
download | linux-d30555853052bbec8497260ba888b7d696bed9b8.tar.xz |
Staging: tidspbridge: Use hashtable implementation
Use upstream hashtable implementation instead of generic code
Signed-off-by: Ivaylo Dimitrov <ivo.g.dimitrov.75@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/staging/tidspbridge/pmgr')
-rw-r--r-- | drivers/staging/tidspbridge/pmgr/dbll.c | 77 |
1 files changed, 36 insertions, 41 deletions
diff --git a/drivers/staging/tidspbridge/pmgr/dbll.c b/drivers/staging/tidspbridge/pmgr/dbll.c index 996a02d27d34..8e21d1e47c9c 100644 --- a/drivers/staging/tidspbridge/pmgr/dbll.c +++ b/drivers/staging/tidspbridge/pmgr/dbll.c @@ -33,9 +33,6 @@ #include <dspbridge/dbll.h> #include <dspbridge/rmm.h> -/* Number of buckets for symbol hash table */ -#define MAXBUCKETS 211 - /* Max buffer length */ #define MAXEXPR 128 @@ -183,8 +180,8 @@ static int execute(struct dynamic_loader_initialize *this, ldr_addr start); static void release(struct dynamic_loader_initialize *this); /* symbol table hash functions */ -static u16 name_hash(void *key, u16 max_bucket); -static bool name_match(void *key, void *sp); +static u32 name_hash(const void *key); +static bool name_match(const void *key, const void *sp); static void sym_delete(void *value); /* Symbol Redefinition */ @@ -277,17 +274,16 @@ bool dbll_get_addr(struct dbll_library_obj *zl_lib, char *name, struct dbll_sym_val **sym_val) { struct dbll_symbol *sym; - bool status = false; sym = (struct dbll_symbol *)gh_find(zl_lib->sym_tab, name); - if (sym != NULL) { - *sym_val = &sym->value; - status = true; - } + if (IS_ERR(sym)) + return false; - dev_dbg(bridge, "%s: lib: %p name: %s paddr: %p, status 0x%x\n", - __func__, zl_lib, name, sym_val, status); - return status; + *sym_val = &sym->value; + + dev_dbg(bridge, "%s: lib: %p name: %s paddr: %p\n", + __func__, zl_lib, name, sym_val); + return true; } /* @@ -312,7 +308,6 @@ bool dbll_get_c_addr(struct dbll_library_obj *zl_lib, char *name, { struct dbll_symbol *sym; char cname[MAXEXPR + 1]; - bool status = false; cname[0] = '_'; @@ -321,13 +316,12 @@ bool dbll_get_c_addr(struct dbll_library_obj *zl_lib, char *name, /* Check for C name, if not found */ sym = (struct dbll_symbol *)gh_find(zl_lib->sym_tab, cname); + if (IS_ERR(sym)) + return false; - if (sym != NULL) { - *sym_val = &sym->value; - status = true; - } + *sym_val = &sym->value; - return status; + return true; } /* @@ -416,12 +410,13 @@ int dbll_load(struct dbll_library_obj *lib, dbll_flags flags, /* Create a hash table for symbols if not already created */ if (zl_lib->sym_tab == NULL) { got_symbols = false; - zl_lib->sym_tab = gh_create(MAXBUCKETS, - sizeof(struct dbll_symbol), + zl_lib->sym_tab = gh_create(sizeof(struct dbll_symbol), name_hash, name_match, sym_delete); - if (zl_lib->sym_tab == NULL) - status = -ENOMEM; + if (IS_ERR(zl_lib->sym_tab)) { + status = PTR_ERR(zl_lib->sym_tab); + zl_lib->sym_tab = NULL; + } } /* @@ -593,10 +588,11 @@ int dbll_open(struct dbll_tar_obj *target, char *file, dbll_flags flags, goto func_cont; zl_lib->sym_tab = - gh_create(MAXBUCKETS, sizeof(struct dbll_symbol), name_hash, - name_match, sym_delete); - if (zl_lib->sym_tab == NULL) { - status = -ENOMEM; + gh_create(sizeof(struct dbll_symbol), name_hash, name_match, + sym_delete); + if (IS_ERR(zl_lib->sym_tab)) { + status = PTR_ERR(zl_lib->sym_tab); + zl_lib->sym_tab = NULL; } else { /* Do a fake load to get symbols - set write func to no_op */ zl_lib->init.dl_init.writemem = no_op; @@ -793,11 +789,10 @@ static int dof_open(struct dbll_library_obj *zl_lib) /* * ======== name_hash ======== */ -static u16 name_hash(void *key, u16 max_bucket) +static u32 name_hash(const void *key) { - u16 ret; - u16 hash; - char *name = (char *)key; + u32 hash; + const char *name = key; hash = 0; @@ -806,19 +801,16 @@ static u16 name_hash(void *key, u16 max_bucket) hash ^= *name++; } - ret = hash % max_bucket; - - return ret; + return hash; } /* * ======== name_match ======== */ -static bool name_match(void *key, void *sp) +static bool name_match(const void *key, const void *sp) { if ((key != NULL) && (sp != NULL)) { - if (strcmp((char *)key, ((struct dbll_symbol *)sp)->name) == - 0) + if (strcmp(key, ((struct dbll_symbol *)sp)->name) == 0) return true; } return false; @@ -937,7 +929,6 @@ static struct dynload_symbol *find_in_symbol_table(struct dynamic_loader_sym *this, const char *name, unsigned moduleid) { - struct dynload_symbol *ret_sym; struct ldr_symbol *ldr_sym = (struct ldr_symbol *)this; struct dbll_library_obj *lib; struct dbll_symbol *sym; @@ -945,8 +936,10 @@ static struct dynload_symbol *find_in_symbol_table(struct dynamic_loader_sym lib = ldr_sym->lib; sym = (struct dbll_symbol *)gh_find(lib->sym_tab, (char *)name); - ret_sym = (struct dynload_symbol *)&sym->value; - return ret_sym; + if (IS_ERR(sym)) + return NULL; + + return (struct dynload_symbol *)&sym->value; } /* @@ -991,8 +984,10 @@ static struct dynload_symbol *dbll_add_to_symbol_table(struct dynamic_loader_sym sym_ptr = (struct dbll_symbol *)gh_insert(lib->sym_tab, (void *)name, (void *)&symbol); - if (sym_ptr == NULL) + if (IS_ERR(sym_ptr)) { kfree(symbol.name); + sym_ptr = NULL; + } } if (sym_ptr != NULL) |