diff options
author | Antonio Quartulli <ordex@autistici.org> | 2011-07-10 00:36:36 +0200 |
---|---|---|
committer | Marek Lindner <lindner_marek@yahoo.de> | 2011-08-22 15:16:19 +0200 |
commit | 1a1f37d9257a4792ca17b28b1c2e4ad15fe95b28 (patch) | |
tree | 5bc0aa0d34b87d1f9b70682f1c54298860ce7d13 /net/batman-adv/hash.h | |
parent | 322a8b034003c0d46d39af85bf24fee27b902f48 (diff) | |
download | linux-3.10-1a1f37d9257a4792ca17b28b1c2e4ad15fe95b28.tar.gz linux-3.10-1a1f37d9257a4792ca17b28b1c2e4ad15fe95b28.tar.bz2 linux-3.10-1a1f37d9257a4792ca17b28b1c2e4ad15fe95b28.zip |
batman-adv: hash_add() has to discriminate on the return value
hash_add() returns 0 on success while returns -1 either on error and on
entry already present. The caller could use such information to select
its behaviour. For this reason it is useful that hash_add() returns -1
in case on error and returns 1 in case of entry already present.
Signed-off-by: Antonio Quartulli <ordex@autistici.org>
Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
Diffstat (limited to 'net/batman-adv/hash.h')
-rw-r--r-- | net/batman-adv/hash.h | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/net/batman-adv/hash.h b/net/batman-adv/hash.h index dd5c9fd7a90..d20aa71ba1e 100644 --- a/net/batman-adv/hash.h +++ b/net/batman-adv/hash.h @@ -76,19 +76,30 @@ static inline void hash_delete(struct hashtable_t *hash, hash_destroy(hash); } -/* adds data to the hashtable. returns 0 on success, -1 on error */ +/** + * hash_add - adds data to the hashtable + * @hash: storage hash table + * @compare: callback to determine if 2 hash elements are identical + * @choose: callback calculating the hash index + * @data: data passed to the aforementioned callbacks as argument + * @data_node: to be added element + * + * Returns 0 on success, 1 if the element already is in the hash + * and -1 on error. + */ + static inline int hash_add(struct hashtable_t *hash, hashdata_compare_cb compare, hashdata_choose_cb choose, const void *data, struct hlist_node *data_node) { - int index; + int index, ret = -1; struct hlist_head *head; struct hlist_node *node; spinlock_t *list_lock; /* spinlock to protect write access */ if (!hash) - goto err; + goto out; index = choose(data, hash->size); head = &hash->table[index]; @@ -99,6 +110,7 @@ static inline int hash_add(struct hashtable_t *hash, if (!compare(node, data)) continue; + ret = 1; goto err_unlock; } rcu_read_unlock(); @@ -108,12 +120,13 @@ static inline int hash_add(struct hashtable_t *hash, hlist_add_head_rcu(data_node, head); spin_unlock_bh(list_lock); - return 0; + ret = 0; + goto out; err_unlock: rcu_read_unlock(); -err: - return -1; +out: + return ret; } /* removes data from hash, if found. returns pointer do data on success, so you |