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


Groups > linux.kernel > #1464906 > unrolled thread

[PATCH] zram: clean up valid_io_request

Started byShawn Lin <shawn.lin@rock-chips.com>
First post2016-08-18 05:20 +0200
Last post2016-08-18 05:30 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] zram: clean up valid_io_request Shawn Lin <shawn.lin@rock-chips.com> - 2016-08-18 05:20 +0200
    Re: [PATCH] zram: clean up valid_io_request Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2016-08-18 05:30 +0200

#1464906 — [PATCH] zram: clean up valid_io_request

FromShawn Lin <shawn.lin@rock-chips.com>
Date2016-08-18 05:20 +0200
Subject[PATCH] zram: clean up valid_io_request
Message-ID<s7m26-2f3-5@gated-at.bofh.it>
Use IS_ALIGNED instead of opencoding to check the unaligned
case. And size is aligned to ZRAM_LOGICAL_BLOCK_SIZE which
will not make end <= start, so we do not need to compare
the start and end.

Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>
---

 drivers/block/zram/zram_drv.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 04365b1..1094e95 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -120,15 +120,15 @@ static inline bool valid_io_request(struct zram *zram,
 	u64 end, bound;
 
 	/* unaligned request */
-	if (unlikely(start & (ZRAM_SECTOR_PER_LOGICAL_BLOCK - 1)))
+	if (unlikely(!IS_ALIGNED(start, ZRAM_SECTOR_PER_LOGICAL_BLOCK)))
 		return false;
-	if (unlikely(size & (ZRAM_LOGICAL_BLOCK_SIZE - 1)))
+	if (unlikely(!IS_ALIGNED(size, ZRAM_LOGICAL_BLOCK_SIZE)))
 		return false;
 
 	end = start + (size >> SECTOR_SHIFT);
 	bound = zram->disksize >> SECTOR_SHIFT;
 	/* out of range range */
-	if (unlikely(start >= bound || end > bound || start > end))
+	if (unlikely(start >= bound || end > bound))
 		return false;
 
 	/* I/O request is valid */
-- 
2.3.7

[toc] | [next] | [standalone]


#1464909

FromSergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
Date2016-08-18 05:30 +0200
Message-ID<s7mbL-2j1-1@gated-at.bofh.it>
In reply to#1464906
Hi,

On (08/18/16 11:08), Shawn Lin wrote:
[..]
> diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
> index 04365b1..1094e95 100644
> --- a/drivers/block/zram/zram_drv.c
> +++ b/drivers/block/zram/zram_drv.c
> @@ -120,15 +120,15 @@ static inline bool valid_io_request(struct zram *zram,
>  	u64 end, bound;
>  
>  	/* unaligned request */
> -	if (unlikely(start & (ZRAM_SECTOR_PER_LOGICAL_BLOCK - 1)))
> +	if (unlikely(!IS_ALIGNED(start, ZRAM_SECTOR_PER_LOGICAL_BLOCK)))
>  		return false;
> -	if (unlikely(size & (ZRAM_LOGICAL_BLOCK_SIZE - 1)))
> +	if (unlikely(!IS_ALIGNED(size, ZRAM_LOGICAL_BLOCK_SIZE)))
>  		return false;

ok.

>  	end = start + (size >> SECTOR_SHIFT);
>  	bound = zram->disksize >> SECTOR_SHIFT;
>  	/* out of range range */
> -	if (unlikely(start >= bound || end > bound || start > end))
> +	if (unlikely(start >= bound || end > bound))
>  		return false;

why did you drop `start > end'? what if `start + (size >> SECTOR_SHIFT)'
overflows and `start' becomes greater than `end'?

	-ss

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web