Minor nits. Nothing major.
On Wed, Dec 25, 2013 at 07:29:52PM +0200, Ivaylo DImitrov wrote:
> From: Ivaylo Dimitrov
>
> Use upstream hashtable implementation instead of generic code
>
> Signed-off-by: Ivaylo Dimitrov
Send from the same email you are using to Sign so we can at least
verify that small thing.
> ---
> drivers/staging/tidspbridge/gen/gh.c | 141
> +++-
> drivers/staging/tidspbridge/include/dspbridge/gh.h |6 +-
> drivers/staging/tidspbridge/pmgr/dbll.c| 47 ---
> 3 files changed, 78 insertions(+), 116 deletions(-)
>
> diff --git a/drivers/staging/tidspbridge/gen/gh.c
> b/drivers/staging/tidspbridge/gen/gh.c
> index 25eaef7..41a0a4f 100644
> --- a/drivers/staging/tidspbridge/gen/gh.c
> +++ b/drivers/staging/tidspbridge/gen/gh.c
> @@ -14,56 +14,46 @@
> * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
> */
>
> -#include
> +#include
> +#include
> +#include
>
> -#include
> -#include
> -
> -struct element {
> - struct element *next;
> +struct gh_node {
> + struct hlist_node hl;
> u8 data[1];
Use a zero size array here so that you can remove the " - 1" from
"sizeof(struct gh_node) - 1 + hash_tab->val_size". (Fix in later
patches).
> };
>
> +#define GH_HASH_ORDER 8
> +
> struct gh_t_hash_tab {
> - u16 max_bucket;
> - u16 val_size;
> - struct element **buckets;
> - u16(*hash) (void *, u16);
> - bool(*match) (void *, void *);
> - void (*delete) (void *);
> + u32 val_size;
> + DECLARE_HASHTABLE(hash_table, GH_HASH_ORDER);
> + u32 (*hash)(void *);
> + bool (*match)(void *, void *);
> + void (*delete)(void *);
> };
>
> -static void noop(void *p);
> -
> /*
> * gh_create
> */
>
> -struct gh_t_hash_tab *gh_create(u16 max_bucket, u16 val_size,
> - u16(*hash) (void *, u16), bool(*match) (void *,
> - void *),
> - void (*delete) (void *))
> +struct gh_t_hash_tab *gh_create(u32 val_size,u32 (*hash)(void *),
> + bool (*match)(void *, void *),
> + void (*delete)(void *))
> {
> struct gh_t_hash_tab *hash_tab;
> - u16 i;
> +
> hash_tab = kzalloc(sizeof(struct gh_t_hash_tab), GFP_KERNEL);
> - if (hash_tab == NULL)
> - return NULL;
> - hash_tab->max_bucket = max_bucket;
> +
Don't put a blank line here between the call and the error handling.
> + if (!hash_tab)
> + return ERR_PTR(-ENOMEM);
> +
> + hash_init(hash_tab->hash_table);
> +
> hash_tab->val_size = val_size;
> hash_tab->hash = hash;
> hash_tab->match = match;
> - hash_tab->delete = delete == NULL ? noop : delete;
> -
> - hash_tab->buckets =
> - kzalloc(sizeof(struct element *) * max_bucket, GFP_KERNEL);
> - if (hash_tab->buckets == NULL) {
> - gh_delete(hash_tab);
> - return NULL;
> - }
> -
> - for (i = 0; i < max_bucket; i++)
> - hash_tab->buckets[i] = NULL;
> + hash_tab->delete = delete;
>
> return hash_tab;
> }
> @@ -73,21 +63,16 @@ struct gh_t_hash_tab *gh_create(u16 max_bucket, u16
> val_size,
> */
> void gh_delete(struct gh_t_hash_tab *hash_tab)
> {
> - struct element *elem, *next;
> - u16 i;
> -
> - if (hash_tab != NULL) {
> - if (hash_tab->buckets != NULL) {
> - for (i = 0; i < hash_tab->max_bucket; i++) {
> - for (elem = hash_tab->buckets[i]; elem != NULL;
> - elem = next) {
> - next = elem->next;
> - (*hash_tab->delete) (elem->data);
> - kfree(elem);
> - }
> - }
> -
> - kfree(hash_tab->buckets);
> + struct gh_node *n;
> + struct hlist_node *tmp;
> + u32 i;
> +
> + if (hash_tab) {
> + hash_for_each_safe(hash_tab->hash_table, i, tmp, n, hl) {
> + hash_del(&n->hl);
> + if(hash_tab->delete)
Use checkpatch.pl.
> + hash_tab->delete(n->data);
> + kfree(n);
> }
>
> kfree(hash_tab);
> @@ -100,16 +85,14 @@ void gh_delete(struct gh_t_hash_tab *hash_tab)
>
> void *gh_find(struct gh_t_hash_tab *hash_tab, void *key)
> {
> - struct element *elem;
> -
> - elem = hash_tab->buckets[(*hash_tab->hash) (key, hash_tab->max_bucket)];
> + struct gh_node *n;
> + u32 key_hash = hash_tab->hash(key);
>
> - for (; elem; elem = elem->next) {
> - if ((*hash_tab->match) (key, elem->data))
> - return elem->data;
> - }
> + hash_for_each_possible(hash_tab->hash_table, n, hl, key