Skip to content

Commit 4dc17b6

Browse files
author
Ming Lei
committed
zram: fix uninitialized ZRAM not releasing backing device
JIRA: https://issues.redhat.com/browse/RHEL-77219 commit 74363ec Author: Kairui Song <kasong@tencent.com> Date: Tue Dec 10 00:57:16 2024 +0800 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/20241209165717.94215-3-ryncsn@gmail.com Fixes: 013bf95 ("zram: add interface to specif backing device") Signed-off-by: Kairui Song <kasong@tencent.com> Reported-by: Desheng Wu <deshengwu@tencent.com> Suggested-by: Sergey Senozhatsky <senozhatsky@chromium.org> Reviewed-by: Sergey Senozhatsky <senozhatsky@chromium.org> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Ming Lei <ming.lei@redhat.com>
1 parent 3db4052 commit 4dc17b6

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
@@ -1299,12 +1299,16 @@ static void zram_meta_free(struct zram *zram, u64 disksize)
12991299
size_t num_pages = disksize >> PAGE_SHIFT;
13001300
size_t index;
13011301

1302+
if (!zram->table)
1303+
return;
1304+
13021305
/* Free all pages that are still in this zram device */
13031306
for (index = 0; index < num_pages; index++)
13041307
zram_free_page(zram, index);
13051308

13061309
zs_destroy_pool(zram->mem_pool);
13071310
vfree(zram->table);
1311+
zram->table = NULL;
13081312
}
13091313

13101314
static bool zram_meta_alloc(struct zram *zram, u64 disksize)
@@ -2131,11 +2135,6 @@ static void zram_reset_device(struct zram *zram)
21312135

21322136
zram->limit_pages = 0;
21332137

2134-
if (!init_done(zram)) {
2135-
up_write(&zram->init_lock);
2136-
return;
2137-
}
2138-
21392138
set_capacity_and_notify(zram->disk, 0);
21402139
part_stat_set_all(zram->disk->part0, 0);
21412140

0 commit comments

Comments
 (0)