Skip to contentSkip to conversation

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

PATCH In review Bob Liu 2 participants 2 messages Feb 24, 2020 Block layer

lore
Share & tools
lore

Bob Liu

author
#0 lore raw

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

Remove unnecessary start/end variables.

---
 block/bio-integrity.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
block/bio-integrity.c +1 -4
index bf62c25..575df98 100644
@@ -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);
Signature · 1 line
2.9.5
maintainer
#1 lore raw
Quoted 20 lines · Bob Liu

Remove unnecessary start/end variables.

---
 block/bio-integrity.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
block/bio-integrity.c +0 -1
index bf62c25..575df98 100644
@@ -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;

block/bio-integrity.c bool bio_integrity_prep(struct bio *bio) · line 243

Quoted 7 lines
block/bio-integrity.c +1 -3
@@ -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.

Signature · 1 line
Jens Axboe