Skip to content

Commit 5387320

Browse files
sderrericvh
authored andcommitted
9pnet: refactor struct p9_fcall alloc code
Signed-off-by: Simon Derr <simon.derr@bull.net> Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
1 parent 17b6fd9 commit 5387320

1 file changed

Lines changed: 18 additions & 17 deletions

File tree

‎net/9p/client.c‎

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,17 @@ static int parse_opts(char *opts, struct p9_client *clnt)
204204
return ret;
205205
}
206206

207+
struct p9_fcall *p9_fcall_alloc(int alloc_msize)
208+
{
209+
struct p9_fcall *fc;
210+
fc = kmalloc(sizeof(struct p9_fcall) + alloc_msize, GFP_NOFS);
211+
if (!fc)
212+
return NULL;
213+
fc->capacity = alloc_msize;
214+
fc->sdata = (char *) fc + sizeof(struct p9_fcall);
215+
return fc;
216+
}
217+
207218
/**
208219
* p9_tag_alloc - lookup/allocate a request by tag
209220
* @c: client session to lookup tag within
@@ -256,29 +267,19 @@ p9_tag_alloc(struct p9_client *c, u16 tag, unsigned int max_size)
256267
col = tag % P9_ROW_MAXTAG;
257268

258269
req = &c->reqs[row][col];
259-
if (!req->tc) {
270+
if (!req->wq) {
260271
req->wq = kmalloc(sizeof(wait_queue_head_t), GFP_NOFS);
261272
if (!req->wq)
262273
goto grow_failed;
263-
264274
init_waitqueue_head(req->wq);
265-
req->tc = kmalloc(sizeof(struct p9_fcall) + alloc_msize,
266-
GFP_NOFS);
267-
if (!req->tc)
268-
goto grow_failed;
269-
270-
req->tc->capacity = alloc_msize;
271-
req->tc->sdata = (char *) req->tc + sizeof(struct p9_fcall);
272275
}
273-
if (!req->rc) {
274-
req->rc = kmalloc(sizeof(struct p9_fcall) + alloc_msize,
275-
GFP_NOFS);
276-
if (!req->rc)
277-
goto grow_failed;
278276

279-
req->rc->capacity = alloc_msize;
280-
req->rc->sdata = (char *) req->rc + sizeof(struct p9_fcall);
281-
}
277+
if (!req->tc)
278+
req->tc = p9_fcall_alloc(alloc_msize);
279+
if (!req->rc)
280+
req->rc = p9_fcall_alloc(alloc_msize);
281+
if (!req->tc || !req->rc)
282+
goto grow_failed;
282283

283284
p9pdu_reset(req->tc);
284285
p9pdu_reset(req->rc);

0 commit comments

Comments
 (0)