[PATCH 1/2] erofs-utils: don't reuse full mapped buffer blocks

Gao Xiang hsiangkao at aol.com
Wed Feb 10 06:13:21 AEDT 2021


From: Gao Xiang <hsiangkao at aol.com>

Otherwise it could cause data corruption since erofs_battach()
doesn't support full buffer blocks (and oob would be misjudged.)

Fixes: 185b0bcdef4b ("erofs-utils: optimize buffer allocation logic")
Signed-off-by: Gao Xiang <hsiangkao at aol.com>
---
 lib/cache.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/lib/cache.c b/lib/cache.c
index 40d3b1f3f4d5..e8840ac5dd31 100644
--- a/lib/cache.c
+++ b/lib/cache.c
@@ -155,8 +155,8 @@ static int erofs_bfind_for_attach(int type, erofs_off_t size,
 				  struct erofs_buffer_block **bbp)
 {
 	struct erofs_buffer_block *cur, *bb;
-	unsigned int used0, usedmax, used;
-	int used_before, ret;
+	unsigned int used0, used_before, usedmax, used;
+	int ret;
 
 	used0 = (size + required_ext) % EROFS_BLKSIZ + inline_ext;
 	/* inline data should be in the same fs block */
@@ -177,7 +177,7 @@ static int erofs_bfind_for_attach(int type, erofs_off_t size,
 
 	used_before = rounddown(EROFS_BLKSIZ -
 				(size + required_ext + inline_ext), alignsize);
-	do {
+	for (; used_before; --used_before) {
 		struct list_head *bt = mapped_buckets[type] + used_before;
 
 		if (list_empty(bt))
@@ -203,7 +203,7 @@ static int erofs_bfind_for_attach(int type, erofs_off_t size,
 		bb = cur;
 		usedmax = used;
 		break;
-	} while (--used_before > 0);
+	}
 
 skip_mapped:
 	/* try to start from the last mapped one, which can be expended */
-- 
2.24.0



More information about the Linux-erofs mailing list