All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/2] staging: zram: remove init_done from zram struct
@ 2013-09-06 13:52 Sergey Senozhatsky
  2013-09-06 14:16 ` Denis Kirjanov
  2013-09-06 14:50 ` Jerome Marchand
  0 siblings, 2 replies; 4+ messages in thread
From: Sergey Senozhatsky @ 2013-09-06 13:52 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Minchan Kim, devel, linux-kernel

`zram->init_done != 0' equals to `zram->meta != NULL', so init_done
can be removed.

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

---

 drivers/staging/zram/zram_drv.c | 18 +++++++-----------
 drivers/staging/zram/zram_drv.h |  1 -
 2 files changed, 7 insertions(+), 12 deletions(-)

diff --git a/drivers/staging/zram/zram_drv.c b/drivers/staging/zram/zram_drv.c
index 17386e2..34b72ea 100644
--- a/drivers/staging/zram/zram_drv.c
+++ b/drivers/staging/zram/zram_drv.c
@@ -60,7 +60,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", zram->meta != NULL);
 }
 
 static ssize_t num_reads_show(struct device *dev,
@@ -133,7 +133,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 (meta)
 		val = zs_get_total_size_bytes(meta->mem_pool);
 	up_read(&zram->init_lock);
 
@@ -556,14 +556,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 (!zram->meta) {
 		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;
@@ -573,7 +571,7 @@ static void zram_reset_device(struct zram *zram, bool reset_capacity)
 		zs_free(meta->mem_pool, handle);
 	}
 
-	zram_meta_free(zram->meta);
+	zram_meta_free(meta);
 	zram->meta = NULL;
 	/* Reset stats */
 	memset(&zram->stats, 0, sizeof(zram->stats));
@@ -602,9 +600,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");
 }
@@ -623,7 +619,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 (zram->meta) {
 		up_write(&zram->init_lock);
 		zram_meta_free(meta);
 		pr_info("Cannot change disksize for initialized device\n");
@@ -731,7 +727,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(!zram->meta))
 		goto error;
 
 	if (!valid_io_request(zram, bio)) {
@@ -880,7 +876,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;
 	/*


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] staging: zram: remove init_done from zram struct
  2013-09-06 13:52 [PATCH 2/2] staging: zram: remove init_done from zram struct Sergey Senozhatsky
@ 2013-09-06 14:16 ` Denis Kirjanov
  2013-09-06 14:50 ` Jerome Marchand
  1 sibling, 0 replies; 4+ messages in thread
From: Denis Kirjanov @ 2013-09-06 14:16 UTC (permalink / raw)
  To: Sergey Senozhatsky; +Cc: Greg Kroah-Hartman, devel, Minchan Kim, linux-kernel

I'm not familiar with the zram code, but looking through the code and
init_done flag it's obvious what is going on rather then looking at
zram->meta field checks.

On 9/6/13, Sergey Senozhatsky <sergey.senozhatsky@gmail.com> wrote:
> `zram->init_done != 0' equals to `zram->meta != NULL', so init_done
> can be removed.
>
> Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
>
> ---
>
>  drivers/staging/zram/zram_drv.c | 18 +++++++-----------
>  drivers/staging/zram/zram_drv.h |  1 -
>  2 files changed, 7 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/staging/zram/zram_drv.c
> b/drivers/staging/zram/zram_drv.c
> index 17386e2..34b72ea 100644
> --- a/drivers/staging/zram/zram_drv.c
> +++ b/drivers/staging/zram/zram_drv.c
> @@ -60,7 +60,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", zram->meta != NULL);
>  }
>
>  static ssize_t num_reads_show(struct device *dev,
> @@ -133,7 +133,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 (meta)
>  		val = zs_get_total_size_bytes(meta->mem_pool);
>  	up_read(&zram->init_lock);
>
> @@ -556,14 +556,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 (!zram->meta) {
>  		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;
> @@ -573,7 +571,7 @@ static void zram_reset_device(struct zram *zram, bool
> reset_capacity)
>  		zs_free(meta->mem_pool, handle);
>  	}
>
> -	zram_meta_free(zram->meta);
> +	zram_meta_free(meta);
>  	zram->meta = NULL;
>  	/* Reset stats */
>  	memset(&zram->stats, 0, sizeof(zram->stats));
> @@ -602,9 +600,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");
>  }
> @@ -623,7 +619,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 (zram->meta) {
>  		up_write(&zram->init_lock);
>  		zram_meta_free(meta);
>  		pr_info("Cannot change disksize for initialized device\n");
> @@ -731,7 +727,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(!zram->meta))
>  		goto error;
>
>  	if (!valid_io_request(zram, bio)) {
> @@ -880,7 +876,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;
>  	/*
>
> _______________________________________________
> devel mailing list
> devel@linuxdriverproject.org
> http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
>


-- 
Regards,
Denis

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] staging: zram: remove init_done from zram struct
  2013-09-06 13:52 [PATCH 2/2] staging: zram: remove init_done from zram struct Sergey Senozhatsky
  2013-09-06 14:16 ` Denis Kirjanov
@ 2013-09-06 14:50 ` Jerome Marchand
  2013-09-06 14:59   ` Sergey Senozhatsky
  1 sibling, 1 reply; 4+ messages in thread
From: Jerome Marchand @ 2013-09-06 14:50 UTC (permalink / raw)
  To: Sergey Senozhatsky; +Cc: Greg Kroah-Hartman, Minchan Kim, devel, linux-kernel

On 09/06/2013 03:52 PM, Sergey Senozhatsky wrote:
> `zram->init_done != 0' equals to `zram->meta != NULL', so init_done
> can be removed.

The name init_done is self explanatory, meta isn't. You could for
instance write a function with an explicit name to test for
initialization.

Jerome

> 
> Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
> 
> ---
> 
>  drivers/staging/zram/zram_drv.c | 18 +++++++-----------
>  drivers/staging/zram/zram_drv.h |  1 -
>  2 files changed, 7 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/staging/zram/zram_drv.c b/drivers/staging/zram/zram_drv.c
> index 17386e2..34b72ea 100644
> --- a/drivers/staging/zram/zram_drv.c
> +++ b/drivers/staging/zram/zram_drv.c
> @@ -60,7 +60,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", zram->meta != NULL);
>  }
>  
>  static ssize_t num_reads_show(struct device *dev,
> @@ -133,7 +133,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 (meta)
>  		val = zs_get_total_size_bytes(meta->mem_pool);
>  	up_read(&zram->init_lock);
>  
> @@ -556,14 +556,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 (!zram->meta) {
>  		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;
> @@ -573,7 +571,7 @@ static void zram_reset_device(struct zram *zram, bool reset_capacity)
>  		zs_free(meta->mem_pool, handle);
>  	}
>  
> -	zram_meta_free(zram->meta);
> +	zram_meta_free(meta);
>  	zram->meta = NULL;
>  	/* Reset stats */
>  	memset(&zram->stats, 0, sizeof(zram->stats));
> @@ -602,9 +600,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");
>  }
> @@ -623,7 +619,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 (zram->meta) {
>  		up_write(&zram->init_lock);
>  		zram_meta_free(meta);
>  		pr_info("Cannot change disksize for initialized device\n");
> @@ -731,7 +727,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(!zram->meta))
>  		goto error;
>  
>  	if (!valid_io_request(zram, bio)) {
> @@ -880,7 +876,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;
>  	/*
> 
> --
> 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/
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] staging: zram: remove init_done from zram struct
  2013-09-06 14:50 ` Jerome Marchand
@ 2013-09-06 14:59   ` Sergey Senozhatsky
  0 siblings, 0 replies; 4+ messages in thread
From: Sergey Senozhatsky @ 2013-09-06 14:59 UTC (permalink / raw)
  To: Jerome Marchand; +Cc: Greg Kroah-Hartman, Minchan Kim, devel, linux-kernel

On (09/06/13 16:50), Jerome Marchand wrote:
> On 09/06/2013 03:52 PM, Sergey Senozhatsky wrote:
> > `zram->init_done != 0' equals to `zram->meta != NULL', so init_done
> > can be removed.
> 
> The name init_done is self explanatory, meta isn't. You could for
> instance write a function with an explicit name to test for
> initialization.

init_done are pretty useless 4 bytes, they just mimic `!!zram->meta'
value (or `zram->meta != NULL'). well, we can have a macro or inline
function to return `zram->meta != NULL'

	-ss

> Jerome
> 
> > 
> > Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
> > 
> > ---
> > 
> >  drivers/staging/zram/zram_drv.c | 18 +++++++-----------
> >  drivers/staging/zram/zram_drv.h |  1 -
> >  2 files changed, 7 insertions(+), 12 deletions(-)
> > 
> > diff --git a/drivers/staging/zram/zram_drv.c b/drivers/staging/zram/zram_drv.c
> > index 17386e2..34b72ea 100644
> > --- a/drivers/staging/zram/zram_drv.c
> > +++ b/drivers/staging/zram/zram_drv.c
> > @@ -60,7 +60,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", zram->meta != NULL);
> >  }
> >  
> >  static ssize_t num_reads_show(struct device *dev,
> > @@ -133,7 +133,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 (meta)
> >  		val = zs_get_total_size_bytes(meta->mem_pool);
> >  	up_read(&zram->init_lock);
> >  
> > @@ -556,14 +556,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 (!zram->meta) {
> >  		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;
> > @@ -573,7 +571,7 @@ static void zram_reset_device(struct zram *zram, bool reset_capacity)
> >  		zs_free(meta->mem_pool, handle);
> >  	}
> >  
> > -	zram_meta_free(zram->meta);
> > +	zram_meta_free(meta);
> >  	zram->meta = NULL;
> >  	/* Reset stats */
> >  	memset(&zram->stats, 0, sizeof(zram->stats));
> > @@ -602,9 +600,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");
> >  }
> > @@ -623,7 +619,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 (zram->meta) {
> >  		up_write(&zram->init_lock);
> >  		zram_meta_free(meta);
> >  		pr_info("Cannot change disksize for initialized device\n");
> > @@ -731,7 +727,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(!zram->meta))
> >  		goto error;
> >  
> >  	if (!valid_io_request(zram, bio)) {
> > @@ -880,7 +876,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;
> >  	/*
> > 
> > --
> > 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/
> > 
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-09-06 15:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-06 13:52 [PATCH 2/2] staging: zram: remove init_done from zram struct Sergey Senozhatsky
2013-09-06 14:16 ` Denis Kirjanov
2013-09-06 14:50 ` Jerome Marchand
2013-09-06 14:59   ` Sergey Senozhatsky

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.