[Devel] [PATCH RH9] dm-ploop: Fix off-by-one in init_be_iter()

Kirill Tkhai ktkhai at virtuozzo.com
Tue Dec 7 17:43:04 MSK 2021


In case of last page completely filled with BAT entries,
the reminder is 0, so @end becomes -1, while it must be 1024.

https://jira.sw.ru/browse/PSBM-136783
Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 drivers/md/dm-ploop.h |   11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/md/dm-ploop.h b/drivers/md/dm-ploop.h
index 54c34bf1231e..96d701f551cf 100644
--- a/drivers/md/dm-ploop.h
+++ b/drivers/md/dm-ploop.h
@@ -464,16 +464,21 @@ static inline bool md_page_cluster_is_in_top_delta(struct ploop *ploop,
 static inline void init_be_iter(u32 nr_be, u32 page_id,
 				u32 *start, u32 *end)
 {
-	u32 last_page = bat_clu_to_page_nr(nr_be - 1);
 	unsigned int count = PAGE_SIZE / sizeof(map_index_t);
+	u32 rem, last_page = bat_clu_to_page_nr(nr_be - 1);
 
 	*start = 0;
 	if (page_id == 0)
 		*start = PLOOP_MAP_OFFSET;
 
 	*end = count - 1;
-	if (page_id == last_page)
-		*end = ((nr_be + PLOOP_MAP_OFFSET) % count) - 1;
+	if (page_id == last_page) {
+		rem = (nr_be + PLOOP_MAP_OFFSET) % count;
+		if (rem)
+			*end = rem - 1;
+		else
+			*end = count - 1;
+	}
 }
 
 static inline void ploop_init_be_iter(struct ploop *ploop, u32 page_id,




More information about the Devel mailing list