aboutsummaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorGanesh Mahendran <opensource.ganesh@gmail.com>2015-02-12 15:00:33 -0800
committerAlex Shi <alex.shi@linaro.org>2015-05-11 21:37:59 +0800
commit837e91c8966924792bf5ba5ef9a62eaa55489ff7 (patch)
tree16c4468c940c49d6f62d5e8510d662abc74ce5f4 /drivers
parent60acd81baccac53be98e07c140a0579a3607be9d (diff)
downloadlinux-linaro-stable-837e91c8966924792bf5ba5ef9a62eaa55489ff7.tar.gz
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: Ganesh Mahendran <opensource.ganesh@gmail.com> Acked-by: Minchan Kim <minchan@kernel.org> Acked-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> Cc: Nitin Gupta <ngupta@vflare.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> (cherry picked from commit 1fec117281d9f5349c35279c9521f4096fa33357) Signed-off-by: Alex Shi <alex.shi@linaro.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/block/zram/zram_drv.c33
1 files changed, 16 insertions, 17 deletions
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 8a1266ce8bbe..3e075d65a158 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -308,8 +308,21 @@ static inline int valid_io_request(struct zram *zram, struct bio *bio)
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);
vfree(meta->table);
kfree(meta);
@@ -708,9 +721,6 @@ static void zram_bio_discard(struct zram *zram, u32 index,
static void zram_reset_device(struct zram *zram, bool reset_capacity)
{
- size_t index;
- struct zram_meta *meta;
-
down_write(&zram->init_lock);
zram->limit_pages = 0;
@@ -720,20 +730,9 @@ static void zram_reset_device(struct zram *zram, bool reset_capacity)
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);
zram->max_comp_streams = 1;
-
- zram_meta_free(zram->meta);
+ zram_meta_free(zram->meta, zram->disksize);
zram->meta = NULL;
/* Reset stats */
memset(&zram->stats, 0, sizeof(zram->stats));
@@ -805,7 +804,7 @@ out_destroy_comp:
up_write(&zram->init_lock);
zcomp_destroy(comp);
out_free_meta:
- zram_meta_free(meta);
+ zram_meta_free(meta, disksize);
return err;
}