Skip to contentSkip to conversation

block: fix offset/size check in bio_trim()

PATCH In review Ming Lei 2 participants 2 messages Apr 12, 2022 – Apr 13, 2022 Block layer

lore
Share & tools
lore

Ming Lei

author
#0 lore raw

PATCH 1/1 block: fix offset/size check in bio_trim()

Unit of bio->bi_iter.bi_size is bytes, but unit of offset/size is sector.

Fix the above issue in checking offset/size in bio_trim().

Fixes e83502ca5f1e ("block: fix argument type of bio_trim()")
Cc Chaitanya Kulkarni <[email protected]>
---
 block/bio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/bio.c +1 -1
index cdd7b2915c53..7c5dcc352db6 100644
@@ -1598,7 +1598,7 @@ EXPORT_SYMBOL(bio_split);
 void bio_trim(struct bio *bio, sector_t offset, sector_t size)
 {
 	if (WARN_ON_ONCE(offset > BIO_MAX_SECTORS || size > BIO_MAX_SECTORS ||
-			 offset + size > bio->bi_iter.bi_size))
+			 offset + size > bio->bi_iter.bi_size >> 9))
 		return;
 
 	size <<= 9;
Signature · 1 line
2.31.1
#1 lore raw
Quoted 4 lines · Ming Lei

Unit of bio->bi_iter.bi_size is bytes, but unit of offset/size is sector.

Fix the above issue in checking offset/size in bio_trim().

Just use bio_sectors() instead.