Skip to content

Commit d3dcf8e

Browse files
Paul Blakeydavem330
authored andcommitted
rhashtable: Fix rhlist duplicates insertion
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>
1 parent 25b5cdf commit d3dcf8e

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

include/linux/rhashtable.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,8 +766,10 @@ static inline void *__rhashtable_insert_fast(
766766
if (!key ||
767767
(params.obj_cmpfn ?
768768
params.obj_cmpfn(&arg, rht_obj(ht, head)) :
769-
rhashtable_compare(&arg, rht_obj(ht, head))))
769+
rhashtable_compare(&arg, rht_obj(ht, head)))) {
770+
pprev = &head->next;
770771
continue;
772+
}
771773

772774
data = rht_obj(ht, head);
773775

lib/rhashtable.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,8 +506,10 @@ static void *rhashtable_lookup_one(struct rhashtable *ht,
506506
if (!key ||
507507
(ht->p.obj_cmpfn ?
508508
ht->p.obj_cmpfn(&arg, rht_obj(ht, head)) :
509-
rhashtable_compare(&arg, rht_obj(ht, head))))
509+
rhashtable_compare(&arg, rht_obj(ht, head)))) {
510+
pprev = &head->next;
510511
continue;
512+
}
511513

512514
if (!ht->rhlist)
513515
return rht_obj(ht, head);

0 commit comments

Comments
 (0)