summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/bcachefs/bkey.h5
-rw-r--r--fs/bcachefs/extents.c4
2 files changed, 5 insertions, 4 deletions
diff --git a/fs/bcachefs/bkey.h b/fs/bcachefs/bkey.h
index 45de61d492a4..ba08d95aae6f 100644
--- a/fs/bcachefs/bkey.h
+++ b/fs/bcachefs/bkey.h
@@ -41,10 +41,7 @@ struct bkey_s {
#define bkey_next(_k) vstruct_next(_k)
-static inline unsigned bkey_val_u64s(const struct bkey *k)
-{
- return k->u64s - BKEY_U64s;
-}
+#define bkey_val_u64s(_k) ((_k)->u64s - BKEY_U64s)
static inline size_t bkey_val_bytes(const struct bkey *k)
{
diff --git a/fs/bcachefs/extents.c b/fs/bcachefs/extents.c
index c5a0d6c8e63a..a5582a6f6ef6 100644
--- a/fs/bcachefs/extents.c
+++ b/fs/bcachefs/extents.c
@@ -1651,6 +1651,10 @@ static bool bch2_extent_merge_inline(struct bch_fs *c,
EBUG_ON(bkey_written(b, m));
+ if (bkey_val_u64s(l) > BKEY_EXTENT_VAL_U64s_MAX ||
+ bkey_val_u64s(r) > BKEY_EXTENT_VAL_U64s_MAX)
+ return BCH_MERGE_NOMERGE;
+
/*
* We need to save copies of both l and r, because we might get a
* partial merge (which modifies both) and then fails to repack