diff --git a/drivers/staging/zram/zram_drv.c b/drivers/staging/zram/zram_drv.c index 1114cadfb960df62b95abfc3d6a99d360aeb37ce..85055c4fc2f261a34afc35da2c55881919edb13f 100644 --- a/drivers/staging/zram/zram_drv.c +++ b/drivers/staging/zram/zram_drv.c @@ -442,16 +442,13 @@ static void zram_make_request(struct request_queue *queue, struct bio *bio) { struct zram *zram = queue->queuedata; - if (unlikely(!zram->init_done) && zram_init_device(zram)) - goto error; - down_read(&zram->init_lock); if (unlikely(!zram->init_done)) - goto error_unlock; + goto error; if (!valid_io_request(zram, bio)) { zram_stat64_inc(zram, &zram->stats.invalid_io); - goto error_unlock; + goto error; } __zram_make_request(zram, bio, bio_data_dir(bio)); @@ -459,9 +456,8 @@ static void zram_make_request(struct request_queue *queue, struct bio *bio) return; -error_unlock: - up_read(&zram->init_lock); error: + up_read(&zram->init_lock); bio_io_error(bio); } @@ -510,18 +506,12 @@ void zram_reset_device(struct zram *zram) up_write(&zram->init_lock); } +/* zram->init_lock should be held */ int zram_init_device(struct zram *zram) { int ret; size_t num_pages; - down_write(&zram->init_lock); - - if (zram->init_done) { - up_write(&zram->init_lock); - return 0; - } - if (zram->disksize > 2 * (totalram_pages << PAGE_SHIFT)) { pr_info( "There is little point creating a zram of greater than " @@ -570,7 +560,6 @@ int zram_init_device(struct zram *zram) } zram->init_done = 1; - up_write(&zram->init_lock); pr_debug("Initialization done!\n"); return 0; @@ -580,7 +569,6 @@ int zram_init_device(struct zram *zram) zram->disksize = 0; fail: __zram_reset_device(zram); - up_write(&zram->init_lock); pr_err("Initialization failed: err=%d\n", ret); return ret; } diff --git a/drivers/staging/zram/zram_sysfs.c b/drivers/staging/zram/zram_sysfs.c index 4143af9fcc1b979f21848ca9692cb3d86a5f4fcc..369db1250f9635955a232176b1db721ff0737053 100644 --- a/drivers/staging/zram/zram_sysfs.c +++ b/drivers/staging/zram/zram_sysfs.c @@ -71,6 +71,7 @@ static ssize_t disksize_store(struct device *dev, zram->disksize = PAGE_ALIGN(disksize); set_capacity(zram->disk, zram->disksize >> SECTOR_SHIFT); + zram_init_device(zram); up_write(&zram->init_lock); return len;