[RFC PATCH v2 10/22] ext2: Test PAGE_SIZE at run time in the rec_len conversions

From: Eric Curtin

Date: Tue Dec 01 2026 - 22:16:53 EST


From: Eric Curtin <eric.curtin@xxxxxxxxxx>

With arm64 boot-time page size selection PAGE_SIZE is not a compile-time
constant, so it cannot be used in #if.

Replace the #if (PAGE_SIZE >= 65536) blocks in ext2_rec_len_from_disk()
and ext2_rec_len_to_disk() with ordinary C conditions. The compiler
still removes the dead code when PAGE_SIZE is constant.

No functional change for compile-time page sizes.

Signed-off-by: Eric Curtin <eric.curtin@xxxxxxxxxx>
---
fs/ext2/dir.c | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/fs/ext2/dir.c b/fs/ext2/dir.c
index 5de32c221a83..267f071188b4 100644
--- a/fs/ext2/dir.c
+++ b/fs/ext2/dir.c
@@ -40,21 +40,19 @@ static inline unsigned ext2_rec_len_from_disk(__le16 dlen)
{
unsigned len = le16_to_cpu(dlen);

-#if (PAGE_SIZE >= 65536)
- if (len == EXT2_MAX_REC_LEN)
+ if (PAGE_SIZE >= 65536 && len == EXT2_MAX_REC_LEN)
return 1 << 16;
-#endif
return len;
}

static inline __le16 ext2_rec_len_to_disk(unsigned len)
{
-#if (PAGE_SIZE >= 65536)
- if (len == (1 << 16))
- return cpu_to_le16(EXT2_MAX_REC_LEN);
- else
- BUG_ON(len > (1 << 16));
-#endif
+ if (PAGE_SIZE >= 65536) {
+ if (len == (1 << 16))
+ return cpu_to_le16(EXT2_MAX_REC_LEN);
+ else
+ BUG_ON(len > (1 << 16));
+ }
return cpu_to_le16(len);
}