lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20121030135831.GD5052@swordfish.minsk.epam.com>
Date:	Tue, 30 Oct 2012 16:58:31 +0300
From:	Sergey Senozhatsky <sergey.senozhatsky@...il.com>
To:	Nitin Gupta <ngupta@...are.org>
Cc:	Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
	linux-kernel@...r.kernel.org
Subject: [PATCH] zram: call zram_init_device() only from disksize_store()

 zram: call zram_init_device() only from disksize_store()

 Call device init only when user set desksize (thus makes it possible to init device)
 and before any RW requests can happen. In that case there is no need to call zram_init_device()
 concurrently from zram_make_request().

 
 Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@...il.com>

---

 drivers/staging/zram/zram_drv.c   | 18 ++++--------------
 drivers/staging/zram/zram_sysfs.c |  4 ++++
 2 files changed, 8 insertions(+), 14 deletions(-)

diff --git a/drivers/staging/zram/zram_drv.c b/drivers/staging/zram/zram_drv.c
index 47f2e3a..a40ecc1 100644
--- a/drivers/staging/zram/zram_drv.c
+++ b/drivers/staging/zram/zram_drv.c
@@ -470,12 +470,11 @@ 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))
+	if (unlikely(!zram->init_done)) {
+		WARN_ON_ONCE(1);
 		goto error_unlock;
+	}
 
 	if (!valid_io_request(zram, bio)) {
 		zram_stat64_inc(zram, &zram->stats.invalid_io);
@@ -486,10 +485,8 @@ static void zram_make_request(struct request_queue *queue, struct bio *bio)
 	up_read(&zram->init_lock);
 
 	return;
-
 error_unlock:
 	up_read(&zram->init_lock);
-error:
 	bio_io_error(bio);
 }
 
@@ -539,12 +536,8 @@ 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);
+	if (zram->init_done)
 		return 0;
-	}
 
 	zram_set_disksize(zram, totalram_pages << PAGE_SHIFT);
 
@@ -584,8 +577,6 @@ int zram_init_device(struct zram *zram)
 	}
 
 	zram->init_done = 1;
-	up_write(&zram->init_lock);
-
 	pr_debug("Initialization done!\n");
 	return 0;
 
@@ -594,7 +585,6 @@ fail_no_table:
 	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 de1eacf..ae95a14 100644
--- a/drivers/staging/zram/zram_sysfs.c
+++ b/drivers/staging/zram/zram_sysfs.c
@@ -71,6 +71,10 @@ static ssize_t disksize_store(struct device *dev,
 
 	zram->disksize = PAGE_ALIGN(disksize);
 	set_capacity(zram->disk, zram->disksize >> SECTOR_SHIFT);
+	if (zram_init_device(zram) != 0) {
+		pr_err("Zram device initialization failed\n");
+		len = -EINVAL;
+	}
 	up_write(&zram->init_lock);
 
 	return len;

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ