Skip to content

Commit 03d8623

Browse files
NeilBrowngregkh
authored andcommitted
sunrpc/cache: drop reference when sunrpc_cache_pipe_upcall() detects a race
commit a6ab1e8126d205238defbb55d23661a3a5c6a0d8 upstream. sunrpc_cache_pipe_upcall() can detect a race if CACHE_PENDING is no longer set. In this case it aborts the queuing of the upcall. However it has already taken a new counted reference on "h" and doesn't "put" it, even though it frees the data structure holding the reference. So let's delay the "cache_get" until we know we need it. Fixes: f9e1aed ("sunrpc/cache: remove races with queuing an upcall.") Signed-off-by: NeilBrown <neilb@suse.com> Signed-off-by: J. Bruce Fields <bfields@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 1f5c4e0 commit 03d8623

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

net/sunrpc/cache.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,14 +1182,14 @@ int sunrpc_cache_pipe_upcall(struct cache_detail *detail, struct cache_head *h)
11821182
}
11831183

11841184
crq->q.reader = 0;
1185-
crq->item = cache_get(h);
11861185
crq->buf = buf;
11871186
crq->len = 0;
11881187
crq->readers = 0;
11891188
spin_lock(&queue_lock);
1190-
if (test_bit(CACHE_PENDING, &h->flags))
1189+
if (test_bit(CACHE_PENDING, &h->flags)) {
1190+
crq->item = cache_get(h);
11911191
list_add_tail(&crq->q.list, &detail->queue);
1192-
else
1192+
} else
11931193
/* Lost a race, no longer PENDING, so don't enqueue */
11941194
ret = -EAGAIN;
11951195
spin_unlock(&queue_lock);

0 commit comments

Comments
 (0)