diff options
Diffstat (limited to 'net/ipv4/inetpeer.c')
-rw-r--r-- | net/ipv4/inetpeer.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c index 58fbc7e2475e..349249fad2db 100644 --- a/net/ipv4/inetpeer.c +++ b/net/ipv4/inetpeer.c | |||
@@ -187,7 +187,12 @@ static struct inet_peer *lookup_rcu_bh(__be32 daddr) | |||
187 | 187 | ||
188 | while (u != peer_avl_empty) { | 188 | while (u != peer_avl_empty) { |
189 | if (daddr == u->v4daddr) { | 189 | if (daddr == u->v4daddr) { |
190 | if (unlikely(!atomic_inc_not_zero(&u->refcnt))) | 190 | /* Before taking a reference, check if this entry was |
191 | * deleted, unlink_from_pool() sets refcnt=-1 to make | ||
192 | * distinction between an unused entry (refcnt=0) and | ||
193 | * a freed one. | ||
194 | */ | ||
195 | if (unlikely(!atomic_add_unless(&u->refcnt, 1, -1))) | ||
191 | u = NULL; | 196 | u = NULL; |
192 | return u; | 197 | return u; |
193 | } | 198 | } |
@@ -322,8 +327,9 @@ static void unlink_from_pool(struct inet_peer *p) | |||
322 | * in cleanup() function to prevent sudden disappearing. If we can | 327 | * in cleanup() function to prevent sudden disappearing. If we can |
323 | * atomically (because of lockless readers) take this last reference, | 328 | * atomically (because of lockless readers) take this last reference, |
324 | * it's safe to remove the node and free it later. | 329 | * it's safe to remove the node and free it later. |
330 | * We use refcnt=-1 to alert lockless readers this entry is deleted. | ||
325 | */ | 331 | */ |
326 | if (atomic_cmpxchg(&p->refcnt, 1, 0) == 1) { | 332 | if (atomic_cmpxchg(&p->refcnt, 1, -1) == 1) { |
327 | struct inet_peer **stack[PEER_MAXDEPTH]; | 333 | struct inet_peer **stack[PEER_MAXDEPTH]; |
328 | struct inet_peer ***stackptr, ***delp; | 334 | struct inet_peer ***stackptr, ***delp; |
329 | if (lookup(p->v4daddr, stack) != p) | 335 | if (lookup(p->v4daddr, stack) != p) |