[PATCH 2/2] dm-bufio: Use struct_size() helper in kmalloc()

From: luoqing

Date: Fri Mar 06 2026 - 03:04:16 EST


From: luoqing <luoqing@xxxxxxxxxx>

Make use of the struct_size() helper instead of an open-coded version,
in order to avoid any potential type mistakes or integer overflows that,
in the worst scenario, could lead to heap overflows.

Signed-off-by: luoqing <luoqing@xxxxxxxxxx>
---
drivers/md/dm-bufio.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/md/dm-bufio.c b/drivers/md/dm-bufio.c
index 60f7badec91f..f8a6b423b4ea 100644
--- a/drivers/md/dm-bufio.c
+++ b/drivers/md/dm-bufio.c
@@ -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(struct_size(c, buffer_tree, num_locks), GFP_KERNEL);
if (!c) {
r = -ENOMEM;
goto bad_client;
--
2.25.1