From: "Roger Pau Monné" <roger.pau@citrix.com>
To: Wenwen Wang <wenwen@cs.uga.edu>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
Jens Axboe <axboe@kernel.dk>,
"moderated list:XEN BLOCK SUBSYSTEM"
<xen-devel@lists.xenproject.org>,
"open list:BLOCK LAYER" <linux-block@vger.kernel.org>,
open list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] xen/blkback: fix memory leaks
Date: Mon, 12 Aug 2019 10:49:11 +0200 [thread overview]
Message-ID: <20190812084911.25vfz6zu5omgtqqe@Air-de-Roger> (raw)
In-Reply-To: <1565544202-3927-1-git-send-email-wenwen@cs.uga.edu>
On Sun, Aug 11, 2019 at 12:23:22PM -0500, Wenwen Wang wrote:
> In read_per_ring_refs(), after 'req' and related memory regions are
> allocated, xen_blkif_map() is invoked to map the shared frame, irq, and
> etc. However, if this mapping process fails, no cleanup is performed,
> leading to memory leaks. To fix this issue, invoke the cleanup before
> returning the error.
>
> Signed-off-by: Wenwen Wang <wenwen@cs.uga.edu>
Thanks!
> ---
> drivers/block/xen-blkback/xenbus.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/block/xen-blkback/xenbus.c b/drivers/block/xen-blkback/xenbus.c
> index 3ac6a5d..b90dbcd 100644
> --- a/drivers/block/xen-blkback/xenbus.c
> +++ b/drivers/block/xen-blkback/xenbus.c
> @@ -965,6 +965,7 @@ static int read_per_ring_refs(struct xen_blkif_ring *ring, const char *dir)
> }
> }
>
> + err = -ENOMEM;
> for (i = 0; i < nr_grefs * XEN_BLKIF_REQS_PER_PAGE; i++) {
> req = kzalloc(sizeof(*req), GFP_KERNEL);
> if (!req)
> @@ -987,7 +988,7 @@ static int read_per_ring_refs(struct xen_blkif_ring *ring, const char *dir)
> err = xen_blkif_map(ring, ring_ref, nr_grefs, evtchn);
You could also move the xen_blkif_map cal before the allocation loop,
since there's nothing in xen_blkif_map that uses the memory allocated
AFAICT, but I'm fine either way.
Acked-by: Roger Pau Monné <roger.pau@citrix.com>
Roger.
next prev parent reply other threads:[~2019-08-12 8:56 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-11 17:23 [PATCH] xen/blkback: fix memory leaks Wenwen Wang
2019-08-12 8:49 ` Roger Pau Monné [this message]
2019-08-12 12:41 ` Boris Ostrovsky
2019-08-12 14:18 ` Jens Axboe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190812084911.25vfz6zu5omgtqqe@Air-de-Roger \
--to=roger.pau@citrix.com \
--cc=axboe@kernel.dk \
--cc=konrad.wilk@oracle.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=wenwen@cs.uga.edu \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).