Skip to content

Commit

Permalink
rhashtable: Fix rhlist duplicates insertion
Browse files Browse the repository at this point in the history
When inserting duplicate objects (those with the same key),
current rhlist implementation messes up the chain pointers by
updating the bucket pointer instead of prev next pointer to the
newly inserted node. This causes missing elements on removal and
travesal.

Fix that by properly updating pprev pointer to point to
the correct rhash_head next pointer.

Issue: 1241076
Change-Id: I86b2c140bcb4aeb10b70a72a267ff590bb2b17e7
Fixes: ca26893 ('rhashtable: Add rhlist interface')
Signed-off-by: Paul Blakey <paulb@mellanox.com>
Acked-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Paul Blakey authored and davem330 committed Mar 7, 2018
1 parent 25b5cdf commit d3dcf8e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion include/linux/rhashtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -766,8 +766,10 @@ static inline void *__rhashtable_insert_fast(
if (!key ||
(params.obj_cmpfn ?
params.obj_cmpfn(&arg, rht_obj(ht, head)) :
rhashtable_compare(&arg, rht_obj(ht, head))))
rhashtable_compare(&arg, rht_obj(ht, head)))) {
pprev = &head->next;
continue;
}

data = rht_obj(ht, head);

Expand Down
4 changes: 3 additions & 1 deletion lib/rhashtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,10 @@ static void *rhashtable_lookup_one(struct rhashtable *ht,
if (!key ||
(ht->p.obj_cmpfn ?
ht->p.obj_cmpfn(&arg, rht_obj(ht, head)) :
rhashtable_compare(&arg, rht_obj(ht, head))))
rhashtable_compare(&arg, rht_obj(ht, head)))) {
pprev = &head->next;
continue;
}

if (!ht->rhlist)
return rht_obj(ht, head);
Expand Down

0 comments on commit d3dcf8e

Please sign in to comment.