Commit 1fec1172 authored by Ganesh Mahendran's avatar Ganesh Mahendran Committed by Linus Torvalds

zram: free meta table in zram_meta_free

zram_meta_alloc() and zram_meta_free() are a pair.  In
zram_meta_alloc(), meta table is allocated.  So it it better to free it
in zram_meta_free().
Signed-off-by: default avatarGanesh Mahendran <opensource.ganesh@gmail.com>
Acked-by: default avatarMinchan Kim <minchan@kernel.org>
Acked-by: default avatarSergey Senozhatsky <sergey.senozhatsky@gmail.com>
Cc: Nitin Gupta <ngupta@vflare.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent b8179958
...@@ -307,8 +307,21 @@ static inline int valid_io_request(struct zram *zram, ...@@ -307,8 +307,21 @@ static inline int valid_io_request(struct zram *zram,
return 1; return 1;
} }
static void zram_meta_free(struct zram_meta *meta) static void zram_meta_free(struct zram_meta *meta, u64 disksize)
{ {
size_t num_pages = disksize >> PAGE_SHIFT;
size_t index;
/* Free all pages that are still in this zram device */
for (index = 0; index < num_pages; index++) {
unsigned long handle = meta->table[index].handle;
if (!handle)
continue;
zs_free(meta->mem_pool, handle);
}
zs_destroy_pool(meta->mem_pool); zs_destroy_pool(meta->mem_pool);
vfree(meta->table); vfree(meta->table);
kfree(meta); kfree(meta);
...@@ -704,9 +717,6 @@ static void zram_bio_discard(struct zram *zram, u32 index, ...@@ -704,9 +717,6 @@ static void zram_bio_discard(struct zram *zram, u32 index,
static void zram_reset_device(struct zram *zram, bool reset_capacity) static void zram_reset_device(struct zram *zram, bool reset_capacity)
{ {
size_t index;
struct zram_meta *meta;
down_write(&zram->init_lock); down_write(&zram->init_lock);
zram->limit_pages = 0; zram->limit_pages = 0;
...@@ -716,20 +726,9 @@ static void zram_reset_device(struct zram *zram, bool reset_capacity) ...@@ -716,20 +726,9 @@ static void zram_reset_device(struct zram *zram, bool reset_capacity)
return; return;
} }
meta = zram->meta;
/* Free all pages that are still in this zram device */
for (index = 0; index < zram->disksize >> PAGE_SHIFT; index++) {
unsigned long handle = meta->table[index].handle;
if (!handle)
continue;
zs_free(meta->mem_pool, handle);
}
zcomp_destroy(zram->comp); zcomp_destroy(zram->comp);
zram->max_comp_streams = 1; zram->max_comp_streams = 1;
zram_meta_free(zram->meta, zram->disksize);
zram_meta_free(zram->meta);
zram->meta = NULL; zram->meta = NULL;
/* Reset stats */ /* Reset stats */
memset(&zram->stats, 0, sizeof(zram->stats)); memset(&zram->stats, 0, sizeof(zram->stats));
...@@ -801,7 +800,7 @@ static ssize_t disksize_store(struct device *dev, ...@@ -801,7 +800,7 @@ static ssize_t disksize_store(struct device *dev,
up_write(&zram->init_lock); up_write(&zram->init_lock);
zcomp_destroy(comp); zcomp_destroy(comp);
out_free_meta: out_free_meta:
zram_meta_free(meta); zram_meta_free(meta, disksize);
return err; return err;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment