* [PATCH] net/9p: fix memory handling/allocation in rdma_request()
@ 2010-09-13 15:53 Davidlohr Bueso
2010-09-14 18:02 ` [V9fs-developer] " Aneesh Kumar K. V
0 siblings, 1 reply; 2+ messages in thread
From: Davidlohr Bueso @ 2010-09-13 15:53 UTC (permalink / raw)
To: ericvh, rminnich, lucho; +Cc: v9fs-developer, LKML
[PATCH] net/9p: fix memory handling/allocation in rdma_request()
Return -ENOMEM when erroring on kmalloc and fix memory leaks when returning on error.
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
---
net/9p/trans_rdma.c | 29 ++++++++++++++++++-----------
1 files changed, 18 insertions(+), 11 deletions(-)
diff --git a/net/9p/trans_rdma.c b/net/9p/trans_rdma.c
index 0ea20c3..17c5ba7 100644
--- a/net/9p/trans_rdma.c
+++ b/net/9p/trans_rdma.c
@@ -426,8 +426,10 @@ static int rdma_request(struct p9_client *client, struct p9_req_t *req)
/* Allocate an fcall for the reply */
rpl_context = kmalloc(sizeof *rpl_context, GFP_KERNEL);
- if (!rpl_context)
+ if (!rpl_context) {
+ err = -ENOMEM;
goto err_close;
+ }
/*
* If the request has a buffer, steal it, otherwise
@@ -445,8 +447,8 @@ static int rdma_request(struct p9_client *client, struct p9_req_t *req)
}
rpl_context->rc = req->rc;
if (!rpl_context->rc) {
- kfree(rpl_context);
- goto err_close;
+ err = -ENOMEM;
+ goto err_free2;
}
/*
@@ -458,11 +460,8 @@ static int rdma_request(struct p9_client *client, struct p9_req_t *req)
*/
if (atomic_inc_return(&rdma->rq_count) <= rdma->rq_depth) {
err = post_recv(client, rpl_context);
- if (err) {
- kfree(rpl_context->rc);
- kfree(rpl_context);
- goto err_close;
- }
+ if (err)
+ goto err_free1;
} else
atomic_dec(&rdma->rq_count);
@@ -471,8 +470,10 @@ static int rdma_request(struct p9_client *client, struct p9_req_t *req)
/* Post the request */
c = kmalloc(sizeof *c, GFP_KERNEL);
- if (!c)
- goto err_close;
+ if (!c) {
+ err = -ENOMEM;
+ goto err_free1;
+ }
c->req = req;
c->busa = ib_dma_map_single(rdma->cm_id->device,
@@ -499,9 +500,15 @@ static int rdma_request(struct p9_client *client, struct p9_req_t *req)
return ib_post_send(rdma->qp, &wr, &bad_wr);
error:
+ kfree(c);
+ kfree(rpl_context->rc);
+ kfree(rpl_context);
P9_DPRINTK(P9_DEBUG_ERROR, "EIO\n");
return -EIO;
-
+ err_free1:
+ kfree(rpl_context->rc);
+ err_free2:
+ kfree(rpl_context);
err_close:
spin_lock_irqsave(&rdma->req_lock, flags);
if (rdma->state < P9_RDMA_CLOSING) {
--
1.7.0.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [V9fs-developer] [PATCH] net/9p: fix memory handling/allocation in rdma_request()
2010-09-13 15:53 [PATCH] net/9p: fix memory handling/allocation in rdma_request() Davidlohr Bueso
@ 2010-09-14 18:02 ` Aneesh Kumar K. V
0 siblings, 0 replies; 2+ messages in thread
From: Aneesh Kumar K. V @ 2010-09-14 18:02 UTC (permalink / raw)
To: dave, ericvh, rminnich, lucho; +Cc: v9fs-developer, LKML
On Mon, 13 Sep 2010 11:53:18 -0400, Davidlohr Bueso <dave@gnu.org> wrote:
> [PATCH] net/9p: fix memory handling/allocation in rdma_request()
>
> Return -ENOMEM when erroring on kmalloc and fix memory leaks when returning on error.
>
> Signed-off-by: Davidlohr Bueso <dave@gnu.org>
Looks good.
Reviewed-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
> ---
> net/9p/trans_rdma.c | 29 ++++++++++++++++++-----------
> 1 files changed, 18 insertions(+), 11 deletions(-)
>
> diff --git a/net/9p/trans_rdma.c b/net/9p/trans_rdma.c
> index 0ea20c3..17c5ba7 100644
> --- a/net/9p/trans_rdma.c
> +++ b/net/9p/trans_rdma.c
> @@ -426,8 +426,10 @@ static int rdma_request(struct p9_client *client, struct p9_req_t *req)
>
> /* Allocate an fcall for the reply */
> rpl_context = kmalloc(sizeof *rpl_context, GFP_KERNEL);
> - if (!rpl_context)
> + if (!rpl_context) {
> + err = -ENOMEM;
> goto err_close;
> + }
>
> /*
> * If the request has a buffer, steal it, otherwise
> @@ -445,8 +447,8 @@ static int rdma_request(struct p9_client *client, struct p9_req_t *req)
> }
> rpl_context->rc = req->rc;
> if (!rpl_context->rc) {
> - kfree(rpl_context);
> - goto err_close;
> + err = -ENOMEM;
> + goto err_free2;
> }
>
> /*
> @@ -458,11 +460,8 @@ static int rdma_request(struct p9_client *client, struct p9_req_t *req)
> */
> if (atomic_inc_return(&rdma->rq_count) <= rdma->rq_depth) {
> err = post_recv(client, rpl_context);
> - if (err) {
> - kfree(rpl_context->rc);
> - kfree(rpl_context);
> - goto err_close;
> - }
> + if (err)
> + goto err_free1;
> } else
> atomic_dec(&rdma->rq_count);
>
> @@ -471,8 +470,10 @@ static int rdma_request(struct p9_client *client, struct p9_req_t *req)
>
> /* Post the request */
> c = kmalloc(sizeof *c, GFP_KERNEL);
> - if (!c)
> - goto err_close;
> + if (!c) {
> + err = -ENOMEM;
> + goto err_free1;
> + }
> c->req = req;
>
> c->busa = ib_dma_map_single(rdma->cm_id->device,
> @@ -499,9 +500,15 @@ static int rdma_request(struct p9_client *client, struct p9_req_t *req)
> return ib_post_send(rdma->qp, &wr, &bad_wr);
>
> error:
> + kfree(c);
> + kfree(rpl_context->rc);
> + kfree(rpl_context);
> P9_DPRINTK(P9_DEBUG_ERROR, "EIO\n");
> return -EIO;
> -
> + err_free1:
> + kfree(rpl_context->rc);
> + err_free2:
> + kfree(rpl_context);
> err_close:
> spin_lock_irqsave(&rdma->req_lock, flags);
> if (rdma->state < P9_RDMA_CLOSING) {
> --
> 1.7.0.4
>
>
>
>
> ------------------------------------------------------------------------------
> Start uncovering the many advantages of virtual appliances
> and start using them to simplify application deployment and
> accelerate your shift to cloud computing
> http://p.sf.net/sfu/novell-sfdev2dev
> _______________________________________________
> V9fs-developer mailing list
> V9fs-developer@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/v9fs-developer
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-09-14 18:03 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-13 15:53 [PATCH] net/9p: fix memory handling/allocation in rdma_request() Davidlohr Bueso
2010-09-14 18:02 ` [V9fs-developer] " Aneesh Kumar K. V
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.