mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-11-27 01:11:31 +00:00
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>
This commit is contained in:
parent
efa8a7014d
commit
15bc0948e7
1 changed files with 5 additions and 2 deletions
|
|
@ -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)))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue