]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
dm-bufio: use kzalloc_flex
authorRosen Penev <rosenp@gmail.com>
Thu, 26 Mar 2026 04:13:54 +0000 (21:13 -0700)
committerMikulas Patocka <mpatocka@redhat.com>
Thu, 26 Mar 2026 17:31:15 +0000 (18:31 +0100)
Avoid manual size calculations and use the proper helper.

Add __counted_by for extra runtime analysis.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
drivers/md/dm-bufio.c

index 60f7badec91f23e0e29f00239da978ba2407e3d6..26fedf5883eff6d2fa1703364713d616e5df07c6 100644 (file)
@@ -391,7 +391,7 @@ struct dm_buffer_cache {
         */
        unsigned int num_locks;
        bool no_sleep;
-       struct buffer_tree trees[];
+       struct buffer_tree trees[] __counted_by(num_locks);
 };
 
 static DEFINE_STATIC_KEY_FALSE(no_sleep_enabled);
@@ -2511,7 +2511,7 @@ struct dm_bufio_client *dm_bufio_client_create(struct block_device *bdev, unsign
        }
 
        num_locks = dm_num_hash_locks();
-       c = kzalloc(sizeof(*c) + (num_locks * sizeof(struct buffer_tree)), GFP_KERNEL);
+       c = kzalloc_flex(*c, cache.trees, num_locks);
        if (!c) {
                r = -ENOMEM;
                goto bad_client;