Skip to content

Commit 6cda128

Browse files
koverstreetmartinetd
authored andcommitted
9p: Drop kref usage
An upcoming patch is going to require passing the client through p9_req_put() -> p9_req_free(), but that's awkward with the kref indirection - so this patch switches to using refcount_t directly. Link: https://lkml.kernel.org/r/20220704014243.153050-1-kent.overstreet@gmail.com Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com> Cc: Eric Van Hensbergen <ericvh@gmail.com> Cc: Latchesar Ionkov <lucho@ionkov.net> Signed-off-by: Dominique Martinet <asmadeus@codewreck.org>
1 parent e3baced commit 6cda128

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

include/net/9p/client.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ enum p9_req_status_t {
7777
struct p9_req_t {
7878
int status;
7979
int t_err;
80-
struct kref refcount;
80+
refcount_t refcount;
8181
wait_queue_head_t wq;
8282
struct p9_fcall tc;
8383
struct p9_fcall rc;
@@ -228,12 +228,12 @@ struct p9_req_t *p9_tag_lookup(struct p9_client *c, u16 tag);
228228

229229
static inline void p9_req_get(struct p9_req_t *r)
230230
{
231-
kref_get(&r->refcount);
231+
refcount_inc(&r->refcount);
232232
}
233233

234234
static inline int p9_req_try_get(struct p9_req_t *r)
235235
{
236-
return kref_get_unless_zero(&r->refcount);
236+
return refcount_inc_not_zero(&r->refcount);
237237
}
238238

239239
int p9_req_put(struct p9_req_t *r);

net/9p/client.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ p9_tag_alloc(struct p9_client *c, int8_t type, unsigned int max_size)
305305
* callback), so p9_client_cb eats the second ref there
306306
* as the pointer is duplicated directly by virtqueue_add_sgs()
307307
*/
308-
refcount_set(&req->refcount.refcount, 2);
308+
refcount_set(&req->refcount, 2);
309309

310310
return req;
311311

@@ -370,18 +370,15 @@ static int p9_tag_remove(struct p9_client *c, struct p9_req_t *r)
370370
return p9_req_put(r);
371371
}
372372

373-
static void p9_req_free(struct kref *ref)
374-
{
375-
struct p9_req_t *r = container_of(ref, struct p9_req_t, refcount);
376-
377-
p9_fcall_fini(&r->tc);
378-
p9_fcall_fini(&r->rc);
379-
kmem_cache_free(p9_req_cache, r);
380-
}
381-
382373
int p9_req_put(struct p9_req_t *r)
383374
{
384-
return kref_put(&r->refcount, p9_req_free);
375+
if (refcount_dec_and_test(&r->refcount)) {
376+
p9_fcall_fini(&r->tc);
377+
p9_fcall_fini(&r->rc);
378+
kmem_cache_free(p9_req_cache, r);
379+
return 1;
380+
}
381+
return 0;
385382
}
386383
EXPORT_SYMBOL(p9_req_put);
387384

0 commit comments

Comments
 (0)