[Concept,6/9] fs: ext4l: Use EXT4_MAX_ORPHAN_FILE_BLOCKS in orphan.c

Message ID 20260107234426.3508161-7-sjg@u-boot.org
State New
Headers
Series Align ext4l with Linux kernel v6.19 implementation |

Commit Message

Simon Glass Jan. 7, 2026, 11:44 p.m. UTC
  From: Simon Glass <simon.glass@canonical.com>

Add the EXT4_MAX_ORPHAN_FILE_BLOCKS constant (512) and use it in the
orphan file size check, matching the Linux kernel implementation.

The previous hardcoded value of (8 << 20) assumed 16KB blocks to get
512 blocks, but the proper calculation uses the actual block size
from the inode.

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
---

 fs/ext4l/orphan.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
  

Patch

diff --git a/fs/ext4l/orphan.c b/fs/ext4l/orphan.c
index 65d0d177c5d..0f5dcca1d96 100644
--- a/fs/ext4l/orphan.c
+++ b/fs/ext4l/orphan.c
@@ -7,6 +7,8 @@ 
 #include "ext4.h"
 #include "ext4_jbd2.h"
 
+#define EXT4_MAX_ORPHAN_FILE_BLOCKS 512
+
 static int ext4_orphan_file_add(handle_t *handle, struct inode *inode)
 {
 	int i, j, start;
@@ -596,7 +598,7 @@  int ext4_init_orphan_info(struct super_block *sb)
 	 * consuming absurd amounts of memory when pinning blocks of orphan
 	 * file in memory.
 	 */
-	if (inode->i_size > 8 << 20) {
+	if (inode->i_size > (EXT4_MAX_ORPHAN_FILE_BLOCKS << inode->i_blkbits)) {
 		ext4_msg(sb, KERN_ERR, "orphan file too big: %llu",
 			 (unsigned long long)inode->i_size);
 		ret = -EFSCORRUPTED;