Skip to content

Commit ea071aa

Browse files
sderrericvh
authored andcommitted
9P: Fix fcall allocation for rdma
The current code assumes that when a request in the request array does have a tc, it also has a rc. This is normally true, but not always : when using RDMA, req->rc will temporarily be set to NULL after the request has been sent. That is usually OK though, as when the reply arrives, req->rc will be reassigned to a sane value before the request is recycled. But there is a catch : if the request is flushed, the reply will never arrive, and req->rc will be NULL, but not req->tc. This patch fixes p9_tag_alloc to take this into account. Signed-off-by: Simon Derr <simon.derr@bull.net> Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
1 parent d9a7385 commit ea071aa

1 file changed

Lines changed: 23 additions & 16 deletions

File tree

‎net/9p/client.c‎

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -258,27 +258,25 @@ p9_tag_alloc(struct p9_client *c, u16 tag, unsigned int max_size)
258258
req = &c->reqs[row][col];
259259
if (!req->tc) {
260260
req->wq = kmalloc(sizeof(wait_queue_head_t), GFP_NOFS);
261-
if (!req->wq) {
262-
pr_err("Couldn't grow tag array\n");
263-
return ERR_PTR(-ENOMEM);
264-
}
261+
if (!req->wq)
262+
goto grow_failed;
263+
265264
init_waitqueue_head(req->wq);
266265
req->tc = kmalloc(sizeof(struct p9_fcall) + alloc_msize,
267266
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);
272+
}
273+
if (!req->rc) {
268274
req->rc = kmalloc(sizeof(struct p9_fcall) + alloc_msize,
269275
GFP_NOFS);
270-
if ((!req->tc) || (!req->rc)) {
271-
pr_err("Couldn't grow tag array\n");
272-
kfree(req->tc);
273-
kfree(req->rc);
274-
kfree(req->wq);
275-
req->tc = req->rc = NULL;
276-
req->wq = NULL;
277-
return ERR_PTR(-ENOMEM);
278-
}
279-
req->tc->capacity = alloc_msize;
276+
if (!req->rc)
277+
goto grow_failed;
278+
280279
req->rc->capacity = alloc_msize;
281-
req->tc->sdata = (char *) req->tc + sizeof(struct p9_fcall);
282280
req->rc->sdata = (char *) req->rc + sizeof(struct p9_fcall);
283281
}
284282

@@ -288,7 +286,16 @@ p9_tag_alloc(struct p9_client *c, u16 tag, unsigned int max_size)
288286
req->tc->tag = tag-1;
289287
req->status = REQ_STATUS_ALLOC;
290288

291-
return &c->reqs[row][col];
289+
return req;
290+
291+
grow_failed:
292+
pr_err("Couldn't grow tag array\n");
293+
kfree(req->tc);
294+
kfree(req->rc);
295+
kfree(req->wq);
296+
req->tc = req->rc = NULL;
297+
req->wq = NULL;
298+
return ERR_PTR(-ENOMEM);
292299
}
293300

294301
/**

0 commit comments

Comments
 (0)