Commit 1fec117281d9f5349c35279c9521f4096fa33357

Authored by Ganesh Mahendran
Committed by Linus Torvalds
1 parent b817995832

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>

Showing 1 changed file with 16 additions and 17 deletions Side-by-side Diff

drivers/block/zram/zram_drv.c
... ... @@ -307,8 +307,21 @@
307 307 return 1;
308 308 }
309 309  
310   -static void zram_meta_free(struct zram_meta *meta)
  310 +static void zram_meta_free(struct zram_meta *meta, u64 disksize)
311 311 {
  312 + size_t num_pages = disksize >> PAGE_SHIFT;
  313 + size_t index;
  314 +
  315 + /* Free all pages that are still in this zram device */
  316 + for (index = 0; index < num_pages; index++) {
  317 + unsigned long handle = meta->table[index].handle;
  318 +
  319 + if (!handle)
  320 + continue;
  321 +
  322 + zs_free(meta->mem_pool, handle);
  323 + }
  324 +
312 325 zs_destroy_pool(meta->mem_pool);
313 326 vfree(meta->table);
314 327 kfree(meta);
... ... @@ -704,9 +717,6 @@
704 717  
705 718 static void zram_reset_device(struct zram *zram, bool reset_capacity)
706 719 {
707   - size_t index;
708   - struct zram_meta *meta;
709   -
710 720 down_write(&zram->init_lock);
711 721  
712 722 zram->limit_pages = 0;
713 723  
... ... @@ -716,20 +726,9 @@
716 726 return;
717 727 }
718 728  
719   - meta = zram->meta;
720   - /* Free all pages that are still in this zram device */
721   - for (index = 0; index < zram->disksize >> PAGE_SHIFT; index++) {
722   - unsigned long handle = meta->table[index].handle;
723   - if (!handle)
724   - continue;
725   -
726   - zs_free(meta->mem_pool, handle);
727   - }
728   -
729 729 zcomp_destroy(zram->comp);
730 730 zram->max_comp_streams = 1;
731   -
732   - zram_meta_free(zram->meta);
  731 + zram_meta_free(zram->meta, zram->disksize);
733 732 zram->meta = NULL;
734 733 /* Reset stats */
735 734 memset(&zram->stats, 0, sizeof(zram->stats));
... ... @@ -801,7 +800,7 @@
801 800 up_write(&zram->init_lock);
802 801 zcomp_destroy(comp);
803 802 out_free_meta:
804   - zram_meta_free(meta);
  803 + zram_meta_free(meta, disksize);
805 804 return err;
806 805 }
807 806