Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1260002

[PATCH] zram: move init_done check to the beginning of disksize_store

From Geliang Tang <geliangtang@163.com>
Newsgroups linux.kernel
Subject [PATCH] zram: move init_done check to the beginning of disksize_store
Date 2015-10-31 16:00 +0100
Message-ID <qpFNo-45K-13@gated-at.bofh.it> (permalink)
Organization linux.* mail to news gateway

Show all headers | View raw


If we set disksize when disksize has been set, we will get the following
error report: "write error: Cannot allocate memory". This is because
disksize_store fails at zram_meta_alloc. This is not what we expect.
To solve this problem, this patch moves init_done check to the beginning
of disksize_store.

Signed-off-by: Geliang Tang <geliangtang@163.com>
---
 drivers/block/zram/zram_drv.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 81a557c..609fc2b 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -1028,6 +1028,14 @@ static ssize_t disksize_store(struct device *dev,
 	struct zram *zram = dev_to_zram(dev);
 	int err;
 
+	down_read(&zram->init_lock);
+	if (init_done(zram)) {
+		up_read(&zram->init_lock);
+		pr_info("Cannot change disksize for initialized device\n");
+		return -EBUSY;
+	}
+	up_read(&zram->init_lock);
+
 	disksize = memparse(buf, NULL);
 	if (!disksize)
 		return -EINVAL;
@@ -1046,12 +1054,6 @@ static ssize_t disksize_store(struct device *dev,
 	}
 
 	down_write(&zram->init_lock);
-	if (init_done(zram)) {
-		pr_info("Cannot change disksize for initialized device\n");
-		err = -EBUSY;
-		goto out_destroy_comp;
-	}
-
 	init_waitqueue_head(&zram->io_done);
 	atomic_set(&zram->refcount, 1);
 	zram->meta = meta;
@@ -1069,9 +1071,6 @@ static ssize_t disksize_store(struct device *dev,
 
 	return len;
 
-out_destroy_comp:
-	up_write(&zram->init_lock);
-	zcomp_destroy(comp);
 out_free_meta:
 	zram_meta_free(meta, disksize);
 	return err;
-- 
2.4.3


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

Back to linux.kernel | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

[PATCH] zram: move init_done check to the beginning of disksize_store Geliang Tang <geliangtang@163.com> - 2015-10-31 16:00 +0100
  Re: [PATCH] zram: move init_done check to the beginning of  disksize_store Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2015-11-02 00:50 +0100
    Re: [PATCH] zram: move init_done check to the beginning of  disksize_store Geliang Tang <geliangtang@163.com> - 2015-11-02 15:00 +0100
      Re: [PATCH] zram: move init_done check to the beginning of  disksize_store Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2015-11-03 01:20 +0100

csiph-web