Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1265112 > unrolled thread

[PATCH 1/2] zram: fix memory freeing in zram_meta_alloc

Started byGeliang Tang <geliangtang@163.com>
First post2015-11-08 16:40 +0100
Last post2015-11-09 01:40 +0100
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH 1/2] zram: fix memory freeing in zram_meta_alloc Geliang Tang <geliangtang@163.com> - 2015-11-08 16:40 +0100
    Re: [PATCH 1/2] zram: fix memory freeing in zram_meta_alloc Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2015-11-09 01:40 +0100

#1265112 — [PATCH 1/2] zram: fix memory freeing in zram_meta_alloc

FromGeliang Tang <geliangtang@163.com>
Date2015-11-08 16:40 +0100
Subject[PATCH 1/2] zram: fix memory freeing in zram_meta_alloc
Message-ID<qsAet-1UC-7@gated-at.bofh.it>
When meta->table is NULL, there is no need to vfree it.

Signed-off-by: Geliang Tang <geliangtang@163.com>
---
 drivers/block/zram/zram_drv.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 81a557c..197a7ad 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -511,7 +511,7 @@ static struct zram_meta *zram_meta_alloc(char *pool_name, u64 disksize)
 	meta->table = vzalloc(num_pages * sizeof(*meta->table));
 	if (!meta->table) {
 		pr_err("Error allocating zram address table\n");
-		goto out_error;
+		goto out_free;
 	}
 
 	meta->mem_pool = zs_create_pool(pool_name, GFP_NOIO | __GFP_HIGHMEM);
@@ -524,6 +524,7 @@ static struct zram_meta *zram_meta_alloc(char *pool_name, u64 disksize)
 
 out_error:
 	vfree(meta->table);
+out_free:
 	kfree(meta);
 	return NULL;
 }
-- 
2.5.0


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1265262

FromSergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
Date2015-11-09 01:40 +0100
Message-ID<qsIF4-7qk-15@gated-at.bofh.it>
In reply to#1265112
On (11/08/15 23:32), Geliang Tang wrote:
> When meta->table is NULL, there is no need to vfree it.
> 

Hi,

So what's the benefit? It's ok to pass a NULL pointer to vfree(). Why
would we add another label? To avoid a valid call on error path?

	-ss

> Signed-off-by: Geliang Tang <geliangtang@163.com>
> ---
>  drivers/block/zram/zram_drv.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
> index 81a557c..197a7ad 100644
> --- a/drivers/block/zram/zram_drv.c
> +++ b/drivers/block/zram/zram_drv.c
> @@ -511,7 +511,7 @@ static struct zram_meta *zram_meta_alloc(char *pool_name, u64 disksize)
>  	meta->table = vzalloc(num_pages * sizeof(*meta->table));
>  	if (!meta->table) {
>  		pr_err("Error allocating zram address table\n");
> -		goto out_error;
> +		goto out_free;
>  	}
>  
>  	meta->mem_pool = zs_create_pool(pool_name, GFP_NOIO | __GFP_HIGHMEM);
> @@ -524,6 +524,7 @@ static struct zram_meta *zram_meta_alloc(char *pool_name, u64 disksize)
>  
>  out_error:
>  	vfree(meta->table);
> +out_free:
>  	kfree(meta);
>  	return NULL;
>  }
> -- 
> 2.5.0
> 
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web