]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
blk-mq: use struct_size() in kmalloc()
authorMehdi Ben Hadj Khelifa <mehdi.benhadjkhelifa@gmail.com>
Sat, 18 Oct 2025 21:38:13 +0000 (22:38 +0100)
committerJens Axboe <axboe@kernel.dk>
Mon, 20 Oct 2025 16:38:56 +0000 (10:38 -0600)
Change struct size calculation to use struct_size()
to align with new recommended practices[1] which quotes:
"Another common case to avoid is calculating the size of a structure with
a trailing array of others structures, as in:

header = kzalloc(sizeof(*header) + count * sizeof(*header->item),
                 GFP_KERNEL);

Instead, use the helper:

header = kzalloc(struct_size(header, item, count), GFP_KERNEL);"

Signed-off-by: Mehdi Ben Hadj Khelifa <mehdi.benhadjkhelifa@gmail.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/blk-mq-sched.c

index e0bed16485c3464d60baa86143f42aa85224033d..97b69fbe26f6c27fbe849809acaf15302841968a 100644 (file)
@@ -466,8 +466,7 @@ struct elevator_tags *blk_mq_alloc_sched_tags(struct blk_mq_tag_set *set,
        else
                nr_tags = nr_hw_queues;
 
-       et = kmalloc(sizeof(struct elevator_tags) +
-                       nr_tags * sizeof(struct blk_mq_tags *), gfp);
+       et = kmalloc(struct_size(et, tags, nr_tags), gfp);
        if (!et)
                return NULL;