]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
btrfs: refactor allocation size calculation in alloc_btrfs_io_context()
authorMehdi Ben Hadj Khelifa <mehdi.benhadjkhelifa@gmail.com>
Tue, 30 Sep 2025 10:03:44 +0000 (11:03 +0100)
committerDavid Sterba <dsterba@suse.com>
Mon, 24 Nov 2025 20:37:36 +0000 (21:37 +0100)
Use struct_size() to replace the open-coded calculation, remove the
comment as use of the helper is self explanatory.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Mehdi Ben Hadj Khelifa <mehdi.benhadjkhelifa@gmail.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/volumes.c

index 2bec544d8ba300093ca5915ca5169847e0ba0625..65b02a93db3149e7a46fde11fb6507899d19380e 100644 (file)
@@ -6076,12 +6076,7 @@ struct btrfs_io_context *alloc_btrfs_io_context(struct btrfs_fs_info *fs_info,
 {
        struct btrfs_io_context *bioc;
 
-       bioc = kzalloc(
-                /* The size of btrfs_io_context */
-               sizeof(struct btrfs_io_context) +
-               /* Plus the variable array for the stripes */
-               sizeof(struct btrfs_io_stripe) * (total_stripes),
-               GFP_NOFS);
+       bioc = kzalloc(struct_size(bioc, stripes, total_stripes), GFP_NOFS);
 
        if (!bioc)
                return NULL;