kernel-janitors.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][next] dm zoned: fix memory leak of newly allocated zone on xa_insert failure
@ 2020-06-03 16:02 Colin King
  2020-06-03 18:18 ` Mike Snitzer
  0 siblings, 1 reply; 2+ messages in thread
From: Colin King @ 2020-06-03 16:02 UTC (permalink / raw)
  To: Alasdair Kergon, Mike Snitzer, dm-devel, Damien Le Moal, Hannes Reinecke
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

Currently if an xa_insert fails then there is a memory lead of the
recently allocated zone object. Fix this by kfree'ing zone before
returning on the error return path.

Addresses-Coverity: ("Resource leak")
Fixes: 1a311efa3916 ("dm zoned: convert to xarray")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/md/dm-zoned-metadata.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/md/dm-zoned-metadata.c b/drivers/md/dm-zoned-metadata.c
index b23ff090c056..130b5a6d9f12 100644
--- a/drivers/md/dm-zoned-metadata.c
+++ b/drivers/md/dm-zoned-metadata.c
@@ -313,8 +313,10 @@ static struct dm_zone *dmz_insert(struct dmz_metadata *zmd,
 	if (!zone)
 		return ERR_PTR(-ENOMEM);
 
-	if (xa_insert(&zmd->zones, zone_id, zone, GFP_KERNEL))
+	if (xa_insert(&zmd->zones, zone_id, zone, GFP_KERNEL)) {
+		kfree(zone);
 		return ERR_PTR(-EBUSY);
+	}
 
 	INIT_LIST_HEAD(&zone->link);
 	atomic_set(&zone->refcount, 0);
-- 
2.25.1

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

* Re: [PATCH][next] dm zoned: fix memory leak of newly allocated zone on xa_insert failure
  2020-06-03 16:02 [PATCH][next] dm zoned: fix memory leak of newly allocated zone on xa_insert failure Colin King
@ 2020-06-03 18:18 ` Mike Snitzer
  0 siblings, 0 replies; 2+ messages in thread
From: Mike Snitzer @ 2020-06-03 18:18 UTC (permalink / raw)
  To: Colin King
  Cc: Alasdair Kergon, dm-devel, Damien Le Moal, Hannes Reinecke,
	kernel-janitors, linux-kernel

On Wed, Jun 03 2020 at 12:02pm -0400,
Colin King <colin.king@canonical.com> wrote:

> From: Colin Ian King <colin.king@canonical.com>
> 
> Currently if an xa_insert fails then there is a memory lead of the
> recently allocated zone object. Fix this by kfree'ing zone before
> returning on the error return path.
> 
> Addresses-Coverity: ("Resource leak")
> Fixes: 1a311efa3916 ("dm zoned: convert to xarray")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  drivers/md/dm-zoned-metadata.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/md/dm-zoned-metadata.c b/drivers/md/dm-zoned-metadata.c
> index b23ff090c056..130b5a6d9f12 100644
> --- a/drivers/md/dm-zoned-metadata.c
> +++ b/drivers/md/dm-zoned-metadata.c
> @@ -313,8 +313,10 @@ static struct dm_zone *dmz_insert(struct dmz_metadata *zmd,
>  	if (!zone)
>  		return ERR_PTR(-ENOMEM);
>  
> -	if (xa_insert(&zmd->zones, zone_id, zone, GFP_KERNEL))
> +	if (xa_insert(&zmd->zones, zone_id, zone, GFP_KERNEL)) {
> +		kfree(zone);
>  		return ERR_PTR(-EBUSY);
> +	}
>  
>  	INIT_LIST_HEAD(&zone->link);
>  	atomic_set(&zone->refcount, 0);
> -- 
> 2.25.1
> 

Thanks, I folded this in.

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

end of thread, other threads:[~2020-06-03 18:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-03 16:02 [PATCH][next] dm zoned: fix memory leak of newly allocated zone on xa_insert failure Colin King
2020-06-03 18:18 ` Mike Snitzer

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).