diff --git a/fs/bcachefs/alloc_background.h b/fs/bcachefs/alloc_background.h
index f8e87c6721b1..764415f9f8b6 100644
--- a/fs/bcachefs/alloc_background.h
+++ b/fs/bcachefs/alloc_background.h
@@ -162,6 +162,8 @@ static inline u64 alloc_lru_idx_read(struct bch_alloc_v4 a)
 
 static inline bool data_type_movable(enum bch_data_type type)
 {
+	if (unlikely(type >= sizeof(unsigned int) * 8))
+		return false;
 	return (1U << type) & DATA_TYPES_MOVABLE;
 }