summaryrefslogtreecommitdiffstats
path: root/fs/bcachefs/bkey.h
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2022-08-15 14:05:44 -0400
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-22 17:09:38 -0400
commit15bc0948e73d9a858a6b69fc4eb34d176436044c (patch)
tree2ba76c58f2f863ed139dd14a75087aff142dd3c6 /fs/bcachefs/bkey.h
parentefa8a7014d288b713781404367b54ef10aa2477f (diff)
downloadlinux-15bc0948e73d9a858a6b69fc4eb34d176436044c.tar.gz
linux-15bc0948e73d9a858a6b69fc4eb34d176436044c.tar.bz2
linux-15bc0948e73d9a858a6b69fc4eb34d176436044c.zip
bcachefs: Add an overflow check in set_bkey_val_u64s()
For now this is just a BUG_ON() - we may want to change this to return an error in the future. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Diffstat (limited to 'fs/bcachefs/bkey.h')
-rw-r--r--fs/bcachefs/bkey.h7
1 files changed, 5 insertions, 2 deletions
diff --git a/fs/bcachefs/bkey.h b/fs/bcachefs/bkey.h
index 6a637a408a9f..8e9405f89537 100644
--- a/fs/bcachefs/bkey.h
+++ b/fs/bcachefs/bkey.h
@@ -50,12 +50,15 @@ static inline size_t bkey_val_bytes(const struct bkey *k)
static inline void set_bkey_val_u64s(struct bkey *k, unsigned val_u64s)
{
- k->u64s = BKEY_U64s + val_u64s;
+ unsigned u64s = BKEY_U64s + val_u64s;
+
+ BUG_ON(u64s > U8_MAX);
+ k->u64s = u64s;
}
static inline void set_bkey_val_bytes(struct bkey *k, unsigned bytes)
{
- k->u64s = BKEY_U64s + DIV_ROUND_UP(bytes, sizeof(u64));
+ set_bkey_val_u64s(k, DIV_ROUND_UP(bytes, sizeof(u64)));
}
#define bkey_val_end(_k) ((void *) (((u64 *) (_k).v) + bkey_val_u64s((_k).k)))