summaryrefslogtreecommitdiff
path: root/fs/bcachefs/inode.c
diff options
context:
space:
mode:
authorJustin Husted <sigstop@gmail.com>2019-10-11 17:20:30 -0700
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-22 17:08:30 -0400
commite3728b50034504e5e64604d72896973374cb1fa5 (patch)
tree59b558932576462c23bc9fac0c87d5d769bf33d8 /fs/bcachefs/inode.c
parente219965586b0e18a12e12fdf37f26eb74bb17bcd (diff)
bcachefs: Initialize padding space after alloc bkey
Packed bkeys are padded up to 64 bit alignment, but the alloc bkey type was not clearing the pad bytes after the last data byte. This left the key possibly containing some random garbage at the end. This problem was found using valgrind. This patch also changes a path with the inode bkey to clear in the same way. Signed-off-by: Justin Husted <sigstop@gmail.com> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/inode.c')
-rw-r--r--fs/bcachefs/inode.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/fs/bcachefs/inode.c b/fs/bcachefs/inode.c
index b0e670cc9d0f..67555db01dc4 100644
--- a/fs/bcachefs/inode.c
+++ b/fs/bcachefs/inode.c
@@ -95,6 +95,7 @@ void bch2_inode_pack(struct bkey_inode_buf *packed,
u8 *end = (void *) &packed[1];
u8 *last_nonzero_field = out;
unsigned nr_fields = 0, last_nonzero_fieldnr = 0;
+ unsigned bytes;
bkey_inode_init(&packed->inode.k_i);
packed->inode.k.p.inode = inode->bi_inum;
@@ -117,10 +118,9 @@ void bch2_inode_pack(struct bkey_inode_buf *packed,
out = last_nonzero_field;
nr_fields = last_nonzero_fieldnr;
- set_bkey_val_bytes(&packed->inode.k, out - (u8 *) &packed->inode.v);
- memset(out, 0,
- (u8 *) &packed->inode.v +
- bkey_val_bytes(&packed->inode.k) - out);
+ bytes = out - (u8 *) &packed->inode.v;
+ set_bkey_val_bytes(&packed->inode.k, bytes);
+ memset_u64s_tail(&packed->inode.v, 0, bytes);
SET_INODE_NR_FIELDS(&packed->inode.v, nr_fields);