Skip to content

Commit 5387815

Browse files
nehebMikulas Patocka
authored andcommitted
dm-bufio: use kzalloc_flex
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>
1 parent fc1d438 commit 5387815

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

drivers/md/dm-bufio.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ struct dm_buffer_cache {
391391
*/
392392
unsigned int num_locks;
393393
bool no_sleep;
394-
struct buffer_tree trees[];
394+
struct buffer_tree trees[] __counted_by(num_locks);
395395
};
396396

397397
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
25112511
}
25122512

25132513
num_locks = dm_num_hash_locks();
2514-
c = kzalloc(sizeof(*c) + (num_locks * sizeof(struct buffer_tree)), GFP_KERNEL);
2514+
c = kzalloc_flex(*c, cache.trees, num_locks);
25152515
if (!c) {
25162516
r = -ENOMEM;
25172517
goto bad_client;

0 commit comments

Comments
 (0)