summaryrefslogtreecommitdiff
path: root/fs/bcachefs/util.h
diff options
context:
space:
mode:
authorJustin Husted <sigstop@gmail.com>2019-10-12 03:20:30 +0300
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-23 00:08:30 +0300
commite3728b50034504e5e64604d72896973374cb1fa5 (patch)
tree59b558932576462c23bc9fac0c87d5d769bf33d8 /fs/bcachefs/util.h
parente219965586b0e18a12e12fdf37f26eb74bb17bcd (diff)
downloadlinux-e3728b50034504e5e64604d72896973374cb1fa5.tar.xz
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/util.h')
-rw-r--r--fs/bcachefs/util.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/fs/bcachefs/util.h b/fs/bcachefs/util.h
index 965b6dd73bfa..33589362f5df 100644
--- a/fs/bcachefs/util.h
+++ b/fs/bcachefs/util.h
@@ -648,6 +648,14 @@ static inline void memmove_u64s(void *dst, const void *src,
__memmove_u64s_up(dst, src, u64s);
}
+/* Set the last few bytes up to a u64 boundary given an offset into a buffer. */
+static inline void memset_u64s_tail(void *s, int c, unsigned bytes)
+{
+ unsigned rem = round_up(bytes, sizeof(u64)) - bytes;
+
+ memset(s + bytes, c, rem);
+}
+
void sort_cmp_size(void *base, size_t num, size_t size,
int (*cmp_func)(const void *, const void *, size_t),
void (*swap_func)(void *, void *, size_t));