diff options
author | Jerome Marchand <jmarchan@redhat.com> | 2011-09-06 15:02:12 +0200 |
---|---|---|
committer | Simon Shields <keepcalm444@gmail.com> | 2016-06-12 21:19:25 +1000 |
commit | 848d1bbacdfe06844f68e8b75ca666ff4604c80c (patch) | |
tree | 46a6bad36c29b4c9ef697aa3c1d549fa69693a94 /drivers/staging | |
parent | 828121d02455e8c6c4574a7ff4d9ac8f803dcc17 (diff) | |
download | kernel_samsung_smdk4412-848d1bbacdfe06844f68e8b75ca666ff4604c80c.tar.gz kernel_samsung_smdk4412-848d1bbacdfe06844f68e8b75ca666ff4604c80c.tar.bz2 kernel_samsung_smdk4412-848d1bbacdfe06844f68e8b75ca666ff4604c80c.zip |
staging: zram: prevent accessing an unallocated table when init fails early
When the allocation of zram->table fails, we set zram->disksize to zero
to prevent accessing the unallocated table entries during cleanup.
However, we currently don't take this precaution when the initialization
fails earlier.
Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/staging')
-rw-r--r-- | drivers/staging/zram/zram_drv.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/drivers/staging/zram/zram_drv.c b/drivers/staging/zram/zram_drv.c index b9d4fd17e06..58829ae7179 100644 --- a/drivers/staging/zram/zram_drv.c +++ b/drivers/staging/zram/zram_drv.c @@ -524,24 +524,22 @@ int zram_init_device(struct zram *zram) if (!zram->compress_workmem) { pr_err("Error allocating compressor working memory!\n"); ret = -ENOMEM; - goto fail; + goto fail_no_table; } zram->compress_buffer = (void *)__get_free_pages(__GFP_ZERO, 1); if (!zram->compress_buffer) { pr_err("Error allocating compressor buffer space\n"); ret = -ENOMEM; - goto fail; + goto fail_no_table; } num_pages = zram->disksize >> PAGE_SHIFT; zram->table = vzalloc(num_pages * sizeof(*zram->table)); if (!zram->table) { pr_err("Error allocating zram address table\n"); - /* To prevent accessing table entries during cleanup */ - zram->disksize = 0; ret = -ENOMEM; - goto fail; + goto fail_no_table; } set_capacity(zram->disk, zram->disksize >> SECTOR_SHIFT); @@ -562,6 +560,9 @@ int zram_init_device(struct zram *zram) pr_debug("Initialization done!\n"); return 0; +fail_no_table: + /* To prevent accessing table entries during cleanup */ + zram->disksize = 0; fail: __zram_reset_device(zram); up_write(&zram->init_lock); |