From: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Jerome Marchand <jmarchan@redhat.com>,
driverdev-devel@linuxdriverproject.org,
Minchan Kim <minchan@kernel.org>,
linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] staging: zram: remove init_done from zram struct (v3)
Date: Wed, 11 Sep 2013 02:19:28 +0300 [thread overview]
Message-ID: <20130910231928.GB2450@swordfish> (raw)
In-Reply-To: <20130910145802.GD19256@mwanda>
`zram->init_done' in fact mimics `zram->meta != NULL' value.
Introduce init_done() function that checks zram->meta (iow,
checks if initialisation was performed), so `zram->init_done'
can be removed.
v3: init_done() in handle_pending_slot_free()
v2: introduce init_done()
Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
---
drivers/staging/zram/zram_drv.c | 23 ++++++++++++-----------
drivers/staging/zram/zram_drv.h | 1 -
2 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/drivers/staging/zram/zram_drv.c b/drivers/staging/zram/zram_drv.c
index 7a2d4de..dcfe07c 100644
--- a/drivers/staging/zram/zram_drv.c
+++ b/drivers/staging/zram/zram_drv.c
@@ -42,6 +42,11 @@ static struct zram *zram_devices;
/* Module params (documentation at end) */
static unsigned int num_devices = 1;
+static inline int init_done(struct zram *zram)
+{
+ return zram->meta != NULL;
+}
+
static inline struct zram *dev_to_zram(struct device *dev)
{
return (struct zram *)dev_to_disk(dev)->private_data;
@@ -60,7 +65,7 @@ static ssize_t initstate_show(struct device *dev,
{
struct zram *zram = dev_to_zram(dev);
- return sprintf(buf, "%u\n", zram->init_done);
+ return sprintf(buf, "%u\n", init_done(zram));
}
static ssize_t num_reads_show(struct device *dev,
@@ -133,7 +138,7 @@ static ssize_t mem_used_total_show(struct device *dev,
struct zram_meta *meta = zram->meta;
down_read(&zram->init_lock);
- if (zram->init_done)
+ if (init_done(zram))
val = zs_get_total_size_bytes(meta->mem_pool);
up_read(&zram->init_lock);
@@ -521,7 +526,7 @@ static void handle_pending_slot_free(struct zram *zram)
while (zram->slot_free_rq) {
free_rq = zram->slot_free_rq;
zram->slot_free_rq = free_rq->next;
- if (zram->init_done)
+ if (init_done(zram))
zram_free_page(zram, free_rq->index);
kfree(free_rq);
}
@@ -553,14 +558,12 @@ static void zram_reset_device(struct zram *zram, bool reset_capacity)
flush_work(&zram->free_work);
down_write(&zram->init_lock);
- if (!zram->init_done) {
+ if (!init_done(zram)) {
up_write(&zram->init_lock);
return;
}
meta = zram->meta;
- zram->init_done = 0;
-
/* Free all pages that are still in this zram device */
for (index = 0; index < zram->disksize >> PAGE_SHIFT; index++) {
unsigned long handle = meta->table[index].handle;
@@ -599,9 +602,7 @@ static void zram_init_device(struct zram *zram, struct zram_meta *meta)
/* zram devices sort of resembles non-rotational disks */
queue_flag_set_unlocked(QUEUE_FLAG_NONROT, zram->disk->queue);
-
zram->meta = meta;
- zram->init_done = 1;
pr_debug("Initialization done!\n");
}
@@ -620,7 +621,7 @@ static ssize_t disksize_store(struct device *dev,
disksize = PAGE_ALIGN(disksize);
meta = zram_meta_alloc(disksize);
down_write(&zram->init_lock);
- if (zram->init_done) {
+ if (init_done(zram)) {
up_write(&zram->init_lock);
zram_meta_free(meta);
pr_info("Cannot change disksize for initialized device\n");
@@ -728,7 +729,7 @@ static void zram_make_request(struct request_queue *queue, struct bio *bio)
struct zram *zram = queue->queuedata;
down_read(&zram->init_lock);
- if (unlikely(!zram->init_done))
+ if (unlikely(!init_done(zram)))
goto error;
if (!valid_io_request(zram, bio)) {
@@ -876,7 +877,7 @@ static int create_device(struct zram *zram, int device_id)
goto out_free_disk;
}
- zram->init_done = 0;
+ zram->meta = NULL;
return 0;
out_free_disk:
diff --git a/drivers/staging/zram/zram_drv.h b/drivers/staging/zram/zram_drv.h
index 97a3acf..b1100cf 100644
--- a/drivers/staging/zram/zram_drv.h
+++ b/drivers/staging/zram/zram_drv.h
@@ -110,7 +110,6 @@ struct zram {
struct request_queue *queue;
struct gendisk *disk;
- int init_done;
/* Prevent concurrent execution of device init, reset and R/W request */
struct rw_semaphore init_lock;
/*
next prev parent reply other threads:[~2013-09-10 23:21 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-06 15:12 [PATCH 1/2] staging: zram: minimize `slot_free_lock' usage (v2) Sergey Senozhatsky
2013-09-09 12:33 ` Dan Carpenter
2013-09-09 12:49 ` Sergey Senozhatsky
2013-09-09 13:21 ` Dan Carpenter
2013-09-09 13:46 ` Jerome Marchand
2013-09-09 16:10 ` Jerome Marchand
2013-09-10 14:34 ` Sergey Senozhatsky
2013-09-10 14:58 ` Dan Carpenter
2013-09-10 15:15 ` Greg Kroah-Hartman
2013-09-10 23:12 ` [PATCH 1/2] staging: zram: fix handle_pending_slot_free() and zram_reset_device() race Sergey Senozhatsky
2013-09-12 22:12 ` Greg KH
2013-09-13 9:17 ` Sergey Senozhatsky
2013-09-16 0:02 ` Minchan Kim
2013-09-17 17:24 ` Sergey Senozhatsky
2013-09-23 4:24 ` Minchan Kim
2013-09-23 8:42 ` Sergey Senozhatsky
2013-09-10 23:19 ` Sergey Senozhatsky [this message]
2013-09-10 23:27 ` [PATCH 1/2] staging: zram: minimize `slot_free_lock' usage (v2) Sergey Senozhatsky
2013-09-09 14:42 ` Sergey Senozhatsky
2013-09-09 14:52 ` Dan Carpenter
2013-09-09 15:09 ` Sergey Senozhatsky
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130910231928.GB2450@swordfish \
--to=sergey.senozhatsky@gmail.com \
--cc=dan.carpenter@oracle.com \
--cc=driverdev-devel@linuxdriverproject.org \
--cc=jmarchan@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=minchan@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.