Skip to contentSkip to conversation

erofs-utils: lib: fix sub-page block handling in erofs_read_superblock()

PATCH New Gao Xiang 1 participant 1 message Jun 20, 2025 Library code

lore
Share & tools
lore

Gao Xiang

author
#0 lore raw

PATCH 1/1 erofs-utils: lib: fix sub-page block handling in erofs_read_superblock()

sbi->sb_size > (1 << sbi->blkszbits) - EROFS_SUPER_OFFSET doesn't work correctly when the block size is 1024.

---
 lib/super.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
lib/super.c +7 -8
index fb644bc..8efef50 100644
@@ -76,13 +76,13 @@ int erofs_read_superblock(struct erofs_sb_info *sbi)
 {
 	u8 data[EROFS_MAX_BLOCK_SIZE];
 	struct erofs_super_block *dsb;
-	int ret;
+	int read, ret;
 
-	sbi->blkszbits = ilog2(EROFS_MAX_BLOCK_SIZE);
-	ret = erofs_blk_read(sbi, 0, data, 0, erofs_blknr(sbi, sizeof(data)));
-	if (ret < 0) {
+	read = erofs_io_pread(&sbi->bdev, data, 0, EROFS_MAX_BLOCK_SIZE);
+	if (read < EROFS_SUPER_END) {
+		ret = read < 0 ? read : -EIO;
 		erofs_err("cannot read erofs superblock: %d", ret);
-		return -EIO;
+		return ret;
 	}
 	dsb = (struct erofs_super_block *)(data + EROFS_SUPER_OFFSET);
 
@@ -105,9 +105,8 @@ int erofs_read_superblock(struct erofs_sb_info *sbi)
 	}
 
 	sbi->sb_size = 128 + dsb->sb_extslots * EROFS_SB_EXTSLOT_SIZE;
-	if (sbi->sb_size > (1 << sbi->blkszbits) - EROFS_SUPER_OFFSET) {
-		erofs_err("invalid sb_extslots %u (more than a fs block)",
-			  dsb->sb_extslots);
+	if (sbi->sb_size > read - EROFS_SUPER_OFFSET) {
+		erofs_err("invalid sb_extslots %u", dsb->sb_extslots);
 		return -EINVAL;
 	}
 	sbi->primarydevice_blocks = le32_to_cpu(dsb->blocks_lo);
Signature · 1 line
2.43.5