Re: [PATCH] fs/netfs: fix reference leak
From: David Howells
Date: Wed Sep 24 2025 - 15:10:41 EST
Max Kellermann <max.kellermann@xxxxxxxxx> wrote:
> > if (!__refcount_sub_and_test(2, &rreq->ref, &r))
> > WARN_ON_ONCE(1);
> > ...
> > trace_netfs_rreq_ref(rreq->debug_id, r, netfs_rreq_trace_put_failed);
>
> You changed the refcount_read() check to an atomic decrement, but at
> this point, nobody cares for the reference counter anymore (and my
> check was just for bug-catching purposes).
> Why bother doing the decrement?
Well, an atomic subtract, but yes. I would at least log the revised refcount
- which actually I've done wrong. The trace line needs r-2, not r, as the
__refcount_*() routines return the original value, not the modified value (the
opposite of the atomic_*() routines).
I think the refcount should probably be 0 when we get to
netfs_free_request_rcu() for consistency (and I've occasionally had a check
there), but I can live with a just a warning and the trace line printing the
current refcount.
David