Skip to contentSkip to conversation

dm-bufio: use kzalloc_flex

PATCH New Rosen Penev 1 participant 1 message Mar 26 Device mapper

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dm-bufio: use kzalloc_flex

Avoid manual size calculations and use the proper helper.

Add __counted_by for extra runtime analysis.

---
 drivers/md/dm-bufio.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/md/dm-bufio.c +2 -2
index 60f7badec91f..26fedf5883ef 100644
@@ -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;
Signature · 1 line
2.53.0