[PATCH v2 1/2] f2fs: use BIT_ULL() for mount option bits

From: Yonggil Song

Date: Tue Jul 07 2026 - 18:51:01 EST


The mount option bitmasks mount_opt.opt and f2fs_fs_context.opt_mask
are unsigned long long, but the bits are manipulated with BIT(), which
is unsigned long. On 32-bit architectures a 33rd mount option would
shift past the type width, which is undefined behaviour:

fs/f2fs/f2fs.h:2945:4: warning: shift count >= width of type
[-Wshift-count-overflow]

Switch test_opt()/set_opt()/clear_opt(), the fs_context helpers and the
direct opt_mask users to BIT_ULL(). No functional change with the
current 32 options; this prepares for adding more.

Reported-by: kernel test robot <lkp@xxxxxxxxx>
Closes: https://lore.kernel.org/oe-kbuild-all/202607071623.ZxOpKv3S-lkp@xxxxxxxxx/
Signed-off-by: Yonggil Song <yonggil.song@xxxxxxxxxxx>
---
fs/f2fs/f2fs.h | 6 +++---
fs/f2fs/super.c | 28 ++++++++++++++--------------
2 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index e40b6b2784ee..20a1e2353f60 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -142,11 +142,11 @@ enum f2fs_mount_opt {

#define F2FS_OPTION(sbi) ((sbi)->mount_opt)
#define clear_opt(sbi, option) \
- (F2FS_OPTION(sbi).opt &= ~BIT(F2FS_MOUNT_##option))
+ (F2FS_OPTION(sbi).opt &= ~BIT_ULL(F2FS_MOUNT_##option))
#define set_opt(sbi, option) \
- (F2FS_OPTION(sbi).opt |= BIT(F2FS_MOUNT_##option))
+ (F2FS_OPTION(sbi).opt |= BIT_ULL(F2FS_MOUNT_##option))
#define test_opt(sbi, option) \
- (F2FS_OPTION(sbi).opt & BIT(F2FS_MOUNT_##option))
+ (F2FS_OPTION(sbi).opt & BIT_ULL(F2FS_MOUNT_##option))

#define ver_after(a, b) (typecheck(unsigned long long, a) && \
typecheck(unsigned long long, b) && \
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index ccf806b676f5..62d3a58cb1b2 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -416,21 +416,21 @@ struct f2fs_fs_context {
static inline void ctx_set_opt(struct f2fs_fs_context *ctx,
enum f2fs_mount_opt flag)
{
- ctx->info.opt |= BIT(flag);
- ctx->opt_mask |= BIT(flag);
+ ctx->info.opt |= BIT_ULL(flag);
+ ctx->opt_mask |= BIT_ULL(flag);
}

static inline void ctx_clear_opt(struct f2fs_fs_context *ctx,
enum f2fs_mount_opt flag)
{
- ctx->info.opt &= ~BIT(flag);
- ctx->opt_mask |= BIT(flag);
+ ctx->info.opt &= ~BIT_ULL(flag);
+ ctx->opt_mask |= BIT_ULL(flag);
}

static inline bool ctx_test_opt(struct f2fs_fs_context *ctx,
enum f2fs_mount_opt flag)
{
- return ctx->info.opt & BIT(flag);
+ return ctx->info.opt & BIT_ULL(flag);
}

void f2fs_printk(struct f2fs_sb_info *sbi, bool limit_rate,
@@ -1422,7 +1422,7 @@ static int f2fs_check_compression(struct fs_context *fc,
ctx_test_opt(ctx, F2FS_MOUNT_COMPRESS_CACHE))
f2fs_info(sbi, "Image doesn't support compression");
clear_compression_spec(ctx);
- ctx->opt_mask &= ~BIT(F2FS_MOUNT_COMPRESS_CACHE);
+ ctx->opt_mask &= ~BIT_ULL(F2FS_MOUNT_COMPRESS_CACHE);
return 0;
}
if (ctx->spec_mask & F2FS_SPEC_compress_extension) {
@@ -1490,43 +1490,43 @@ static int f2fs_check_opt_consistency(struct fs_context *fc,
return -EINVAL;

if (f2fs_hw_should_discard(sbi) &&
- (ctx->opt_mask & BIT(F2FS_MOUNT_DISCARD)) &&
+ (ctx->opt_mask & BIT_ULL(F2FS_MOUNT_DISCARD)) &&
!ctx_test_opt(ctx, F2FS_MOUNT_DISCARD)) {
f2fs_warn(sbi, "discard is required for zoned block devices");
return -EINVAL;
}

if (!f2fs_hw_support_discard(sbi) &&
- (ctx->opt_mask & BIT(F2FS_MOUNT_DISCARD)) &&
+ (ctx->opt_mask & BIT_ULL(F2FS_MOUNT_DISCARD)) &&
ctx_test_opt(ctx, F2FS_MOUNT_DISCARD)) {
f2fs_warn(sbi, "device does not support discard");
ctx_clear_opt(ctx, F2FS_MOUNT_DISCARD);
- ctx->opt_mask &= ~BIT(F2FS_MOUNT_DISCARD);
+ ctx->opt_mask &= ~BIT_ULL(F2FS_MOUNT_DISCARD);
}

if (f2fs_sb_has_device_alias(sbi) &&
- (ctx->opt_mask & BIT(F2FS_MOUNT_READ_EXTENT_CACHE)) &&
+ (ctx->opt_mask & BIT_ULL(F2FS_MOUNT_READ_EXTENT_CACHE)) &&
!ctx_test_opt(ctx, F2FS_MOUNT_READ_EXTENT_CACHE)) {
f2fs_err(sbi, "device aliasing requires extent cache");
return -EINVAL;
}

if (test_opt(sbi, RESERVE_ROOT) &&
- (ctx->opt_mask & BIT(F2FS_MOUNT_RESERVE_ROOT)) &&
+ (ctx->opt_mask & BIT_ULL(F2FS_MOUNT_RESERVE_ROOT)) &&
ctx_test_opt(ctx, F2FS_MOUNT_RESERVE_ROOT)) {
f2fs_info(sbi, "Preserve previous reserve_root=%u",
F2FS_OPTION(sbi).root_reserved_blocks);
ctx_clear_opt(ctx, F2FS_MOUNT_RESERVE_ROOT);
- ctx->opt_mask &= ~BIT(F2FS_MOUNT_RESERVE_ROOT);
+ ctx->opt_mask &= ~BIT_ULL(F2FS_MOUNT_RESERVE_ROOT);
ctx->spec_mask &= ~F2FS_SPEC_reserve_root;
}
if (test_opt(sbi, RESERVE_NODE) &&
- (ctx->opt_mask & BIT(F2FS_MOUNT_RESERVE_NODE)) &&
+ (ctx->opt_mask & BIT_ULL(F2FS_MOUNT_RESERVE_NODE)) &&
ctx_test_opt(ctx, F2FS_MOUNT_RESERVE_NODE)) {
f2fs_info(sbi, "Preserve previous reserve_node=%u",
F2FS_OPTION(sbi).root_reserved_nodes);
ctx_clear_opt(ctx, F2FS_MOUNT_RESERVE_NODE);
- ctx->opt_mask &= ~BIT(F2FS_MOUNT_RESERVE_NODE);
+ ctx->opt_mask &= ~BIT_ULL(F2FS_MOUNT_RESERVE_NODE);
ctx->spec_mask &= ~F2FS_SPEC_reserve_node;
}


base-commit: cb8ff3ead9a3fc43727980be58c7099506f65261
--
2.43.0