[Devel] [PATCH RH8] cbt: Fix off-by-one in map_required_size()
Kirill Tkhai
ktkhai at virtuozzo.com
Tue Sep 28 19:43:01 MSK 2021
Instead of:
return DIV_ROUND_UP(bit, 8) + page * PAGE_SIZE;
we have to have:
return DIV_ROUND_UP(bit, 8) + (page - 1) * PAGE_SIZE;
But instead of that we fix @page to be enumerated
from 0 in standard C way.
Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
block/blk-cbt.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/block/blk-cbt.c b/block/blk-cbt.c
index 1ccc393f1419..e8eee11a87ba 100644
--- a/block/blk-cbt.c
+++ b/block/blk-cbt.c
@@ -315,15 +315,14 @@ static unsigned long map_required_size(struct page **map, unsigned long block_ma
{
unsigned long bit, page, npages = NR_PAGES(block_max);
- for (page = npages; page > 0; page--) {
- if (map[page-1])
+ for (page = npages - 1; page != ULONG_MAX; page--) {
+ if (map[page])
break;
}
-
- if (page == 0)
+ if (page == ULONG_MAX)
return 0;
- bit = find_last_bit(page_address(map[page - 1]), PAGE_SIZE);
+ bit = find_last_bit(page_address(map[page]), PAGE_SIZE);
if (bit >= PAGE_SIZE)
bit = 0; /* Not found */
else
More information about the Devel
mailing list