diff mbox series

block/bio-integrity: simplify the way of calculate nr_pages

Message ID 20200224131258.18156-1-bob.liu@oracle.com (mailing list archive)
State New, archived
Headers show
Series block/bio-integrity: simplify the way of calculate nr_pages | expand

Commit Message

Bob Liu Feb. 24, 2020, 1:12 p.m. UTC
Remove unnecessary start/end variables.

Signed-off-by: Bob Liu <bob.liu@oracle.com>
---
 block/bio-integrity.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

Comments

Jens Axboe Feb. 24, 2020, 4:40 p.m. UTC | #1
On 2/24/20 6:12 AM, Bob Liu wrote:
> Remove unnecessary start/end variables.
> 
> Signed-off-by: Bob Liu <bob.liu@oracle.com>
> ---
>  block/bio-integrity.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/block/bio-integrity.c b/block/bio-integrity.c
> index bf62c25..575df98 100644
> --- a/block/bio-integrity.c
> +++ b/block/bio-integrity.c
> @@ -202,7 +202,6 @@ bool bio_integrity_prep(struct bio *bio)
>  	struct blk_integrity *bi = blk_get_integrity(bio->bi_disk);
>  	struct request_queue *q = bio->bi_disk->queue;
>  	void *buf;
> -	unsigned long start, end;
>  	unsigned int len, nr_pages;
>  	unsigned int bytes, offset, i;
>  	unsigned int intervals;
> @@ -241,9 +240,7 @@ bool bio_integrity_prep(struct bio *bio)
>  		goto err_end_io;
>  	}
>  
> -	end = (((unsigned long) buf) + len + PAGE_SIZE - 1) >> PAGE_SHIFT;
> -	start = ((unsigned long) buf) >> PAGE_SHIFT;
> -	nr_pages = end - start;
> +	nr_pages = (len + PAGE_SIZE - 1) >> PAGE_SHIFT;

This is incorrect if you straddle a page boundary, the existing code is
correct.
diff mbox series

Patch

diff --git a/block/bio-integrity.c b/block/bio-integrity.c
index bf62c25..575df98 100644
--- a/block/bio-integrity.c
+++ b/block/bio-integrity.c
@@ -202,7 +202,6 @@  bool bio_integrity_prep(struct bio *bio)
 	struct blk_integrity *bi = blk_get_integrity(bio->bi_disk);
 	struct request_queue *q = bio->bi_disk->queue;
 	void *buf;
-	unsigned long start, end;
 	unsigned int len, nr_pages;
 	unsigned int bytes, offset, i;
 	unsigned int intervals;
@@ -241,9 +240,7 @@  bool bio_integrity_prep(struct bio *bio)
 		goto err_end_io;
 	}
 
-	end = (((unsigned long) buf) + len + PAGE_SIZE - 1) >> PAGE_SHIFT;
-	start = ((unsigned long) buf) >> PAGE_SHIFT;
-	nr_pages = end - start;
+	nr_pages = (len + PAGE_SIZE - 1) >> PAGE_SHIFT;
 
 	/* Allocate bio integrity payload and integrity vectors */
 	bip = bio_integrity_alloc(bio, GFP_NOIO, nr_pages);