Skip to content

Commit 74363ec

Browse files
ryncsnakpm00
authored andcommitted
zram: fix uninitialized ZRAM not releasing backing device
Setting backing device is done before ZRAM initialization. If we set the backing device, then remove the ZRAM module without initializing the device, the backing device reference will be leaked and the device will be hold forever. Fix this by always reset the ZRAM fully on rmmod or reset store. Link: https://lkml.kernel.org/r/[email protected] Fixes: 013bf95 ("zram: add interface to specif backing device") Signed-off-by: Kairui Song <[email protected]> Reported-by: Desheng Wu <[email protected]> Suggested-by: Sergey Senozhatsky <[email protected]> Reviewed-by: Sergey Senozhatsky <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent be48c41 commit 74363ec

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

drivers/block/zram/zram_drv.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,12 +1444,16 @@ static void zram_meta_free(struct zram *zram, u64 disksize)
14441444
size_t num_pages = disksize >> PAGE_SHIFT;
14451445
size_t index;
14461446

1447+
if (!zram->table)
1448+
return;
1449+
14471450
/* Free all pages that are still in this zram device */
14481451
for (index = 0; index < num_pages; index++)
14491452
zram_free_page(zram, index);
14501453

14511454
zs_destroy_pool(zram->mem_pool);
14521455
vfree(zram->table);
1456+
zram->table = NULL;
14531457
}
14541458

14551459
static bool zram_meta_alloc(struct zram *zram, u64 disksize)
@@ -2326,11 +2330,6 @@ static void zram_reset_device(struct zram *zram)
23262330

23272331
zram->limit_pages = 0;
23282332

2329-
if (!init_done(zram)) {
2330-
up_write(&zram->init_lock);
2331-
return;
2332-
}
2333-
23342333
set_capacity_and_notify(zram->disk, 0);
23352334
part_stat_set_all(zram->disk->part0, 0);
23362335

0 commit comments

Comments
 (0)