All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xen/blkback: fix memory leaks
@ 2019-08-11 17:23 ` Wenwen Wang
  0 siblings, 0 replies; 8+ messages in thread
From: Wenwen Wang @ 2019-08-11 17:23 UTC (permalink / raw)
  To: Wenwen Wang
  Cc: Konrad Rzeszutek Wilk, Roger Pau Monné,
	Jens Axboe, moderated list:XEN BLOCK SUBSYSTEM,
	open list:BLOCK LAYER, open list

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>
---
 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);
 	if (err) {
 		xenbus_dev_fatal(dev, err, "mapping ring-ref port %u", evtchn);
-		return err;
+		goto fail;
 	}
 
 	return 0;
@@ -1007,8 +1008,7 @@ static int read_per_ring_refs(struct xen_blkif_ring *ring, const char *dir)
 		}
 		kfree(req);
 	}
-	return -ENOMEM;
-
+	return err;
 }
 
 static int connect_ring(struct backend_info *be)
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [Xen-devel] [PATCH] xen/blkback: fix memory leaks
@ 2019-08-11 17:23 ` Wenwen Wang
  0 siblings, 0 replies; 8+ messages in thread
From: Wenwen Wang @ 2019-08-11 17:23 UTC (permalink / raw)
  To: Wenwen Wang
  Cc: Jens Axboe, Konrad Rzeszutek Wilk, open list,
	open list:BLOCK LAYER, moderated list:XEN BLOCK SUBSYSTEM,
	Roger Pau Monné

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>
---
 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);
 	if (err) {
 		xenbus_dev_fatal(dev, err, "mapping ring-ref port %u", evtchn);
-		return err;
+		goto fail;
 	}
 
 	return 0;
@@ -1007,8 +1008,7 @@ static int read_per_ring_refs(struct xen_blkif_ring *ring, const char *dir)
 		}
 		kfree(req);
 	}
-	return -ENOMEM;
-
+	return err;
 }
 
 static int connect_ring(struct backend_info *be)
-- 
2.7.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] xen/blkback: fix memory leaks
  2019-08-11 17:23 ` [Xen-devel] " Wenwen Wang
@ 2019-08-12  8:49   ` Roger Pau Monné
  -1 siblings, 0 replies; 8+ messages in thread
From: Roger Pau Monné @ 2019-08-12  8:49 UTC (permalink / raw)
  To: Wenwen Wang
  Cc: Konrad Rzeszutek Wilk, Jens Axboe,
	moderated list:XEN BLOCK SUBSYSTEM, open list:BLOCK LAYER,
	open list

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.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Xen-devel] [PATCH] xen/blkback: fix memory leaks
@ 2019-08-12  8:49   ` Roger Pau Monné
  0 siblings, 0 replies; 8+ messages in thread
From: Roger Pau Monné @ 2019-08-12  8:49 UTC (permalink / raw)
  To: Wenwen Wang
  Cc: Jens Axboe, moderated list:XEN BLOCK SUBSYSTEM,
	open list:BLOCK LAYER, open list, Konrad Rzeszutek Wilk

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.

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] xen/blkback: fix memory leaks
  2019-08-11 17:23 ` [Xen-devel] " Wenwen Wang
@ 2019-08-12 12:41   ` Boris Ostrovsky
  -1 siblings, 0 replies; 8+ messages in thread
From: Boris Ostrovsky @ 2019-08-12 12:41 UTC (permalink / raw)
  To: Wenwen Wang
  Cc: Konrad Rzeszutek Wilk, Roger Pau Monné,
	Jens Axboe, moderated list:XEN BLOCK SUBSYSTEM,
	open list:BLOCK LAYER, open list

On 8/11/19 1:23 PM, 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.


Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Xen-devel] [PATCH] xen/blkback: fix memory leaks
@ 2019-08-12 12:41   ` Boris Ostrovsky
  0 siblings, 0 replies; 8+ messages in thread
From: Boris Ostrovsky @ 2019-08-12 12:41 UTC (permalink / raw)
  To: Wenwen Wang
  Cc: Jens Axboe, Konrad Rzeszutek Wilk, open list,
	open list:BLOCK LAYER, moderated list:XEN BLOCK SUBSYSTEM,
	Roger Pau Monné

On 8/11/19 1:23 PM, 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.


Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] xen/blkback: fix memory leaks
  2019-08-11 17:23 ` [Xen-devel] " Wenwen Wang
@ 2019-08-12 14:18   ` Jens Axboe
  -1 siblings, 0 replies; 8+ messages in thread
From: Jens Axboe @ 2019-08-12 14:18 UTC (permalink / raw)
  To: Wenwen Wang
  Cc: Konrad Rzeszutek Wilk, Roger Pau Monné,
	moderated list:XEN BLOCK SUBSYSTEM, open list:BLOCK LAYER,
	open list

On 8/11/19 10:23 AM, 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.

Applied, thanks.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Xen-devel] [PATCH] xen/blkback: fix memory leaks
@ 2019-08-12 14:18   ` Jens Axboe
  0 siblings, 0 replies; 8+ messages in thread
From: Jens Axboe @ 2019-08-12 14:18 UTC (permalink / raw)
  To: Wenwen Wang
  Cc: open list:BLOCK LAYER, moderated list:XEN BLOCK SUBSYSTEM,
	Roger Pau Monné,
	open list, Konrad Rzeszutek Wilk

On 8/11/19 10:23 AM, 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.

Applied, thanks.

-- 
Jens Axboe


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2019-08-13  6:54 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-11 17:23 [PATCH] xen/blkback: fix memory leaks Wenwen Wang
2019-08-11 17:23 ` [Xen-devel] " Wenwen Wang
2019-08-12  8:49 ` Roger Pau Monné
2019-08-12  8:49   ` [Xen-devel] " Roger Pau Monné
2019-08-12 12:41 ` Boris Ostrovsky
2019-08-12 12:41   ` [Xen-devel] " Boris Ostrovsky
2019-08-12 14:18 ` Jens Axboe
2019-08-12 14:18   ` [Xen-devel] " Jens Axboe

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.