summaryrefslogtreecommitdiffstats
path: root/fs/btrfs
diff options
context:
space:
mode:
authorKees Cook <keescook@chromium.org>2022-09-23 13:28:13 -0700
committerKees Cook <keescook@chromium.org>2022-11-01 10:04:52 -0700
commit905889bc6c842d18f369bf2834cf7219f32709ae (patch)
tree2ea427965285e54d4758fafa0b82896d19f63d40 /fs/btrfs
parentcd536db050993f7c220a6cfb01de5356032b6f8e (diff)
downloadlinux-905889bc6c842d18f369bf2834cf7219f32709ae.tar.gz
linux-905889bc6c842d18f369bf2834cf7219f32709ae.tar.bz2
linux-905889bc6c842d18f369bf2834cf7219f32709ae.zip
btrfs: send: Proactively round up to kmalloc bucket size
Instead of discovering the kmalloc bucket size _after_ allocation, round up proactively so the allocation is explicitly made for the full size, allowing the compiler to correctly reason about the resulting size of the buffer through the existing __alloc_size() hint. Cc: Chris Mason <clm@fb.com> Cc: Josef Bacik <josef@toxicpanda.com> Cc: linux-btrfs@vger.kernel.org Acked-by: David Sterba <dsterba@suse.com> Link: https://lore.kernel.org/lkml/20220922133014.GI32411@suse.cz Signed-off-by: Kees Cook <keescook@chromium.org> Link: https://lore.kernel.org/r/20220923202822.2667581-8-keescook@chromium.org
Diffstat (limited to 'fs/btrfs')
-rw-r--r--fs/btrfs/send.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c
index 4ef4167072b8..f53e8049473d 100644
--- a/fs/btrfs/send.c
+++ b/fs/btrfs/send.c
@@ -439,6 +439,11 @@ static int fs_path_ensure_buf(struct fs_path *p, int len)
old_buf_len = p->buf_len;
/*
+ * Allocate to the next largest kmalloc bucket size, to let
+ * the fast path happen most of the time.
+ */
+ len = kmalloc_size_roundup(len);
+ /*
* First time the inline_buf does not suffice
*/
if (p->buf == p->inline_buf) {
@@ -451,11 +456,7 @@ static int fs_path_ensure_buf(struct fs_path *p, int len)
if (!tmp_buf)
return -ENOMEM;
p->buf = tmp_buf;
- /*
- * The real size of the buffer is bigger, this will let the fast path
- * happen most of the time
- */
- p->buf_len = ksize(p->buf);
+ p->buf_len = len;
if (p->reversed) {
tmp_buf = p->buf + old_buf_len - path_len - 1;