* [PATCH] zram: clean up valid_io_request
@ 2016-08-18 3:08 Shawn Lin
2016-08-18 3:25 ` Sergey Senozhatsky
0 siblings, 1 reply; 2+ messages in thread
From: Shawn Lin @ 2016-08-18 3:08 UTC (permalink / raw)
To: Minchan Kim
Cc: Nitin Gupta, Sergey Senozhatsky, linux-kernel, Andrew Morton,
Shawn Lin
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] zram: clean up valid_io_request
2016-08-18 3:08 [PATCH] zram: clean up valid_io_request Shawn Lin
@ 2016-08-18 3:25 ` Sergey Senozhatsky
0 siblings, 0 replies; 2+ messages in thread
From: Sergey Senozhatsky @ 2016-08-18 3:25 UTC (permalink / raw)
To: Shawn Lin
Cc: Minchan Kim, Nitin Gupta, Sergey Senozhatsky, linux-kernel,
Andrew Morton
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-08-18 3:25 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-08-18 3:08 [PATCH] zram: clean up valid_io_request Shawn Lin
2016-08-18 3:25 ` Sergey Senozhatsky
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox