Skip to content

Commit 1f4fe21

Browse files
GustavoARSilvaaxboe
authored andcommitted
block: bio: Use struct_size() in kmalloc()
Make use of the struct_size() helper instead of an open-coded version in order to avoid any potential type mistakes. This code was detected with the help of Coccinelle and, audited and fixed manually. Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> Addresses-KSPP-ID: KSPP/linux#83 Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 85e0cbb commit 1f4fe21

1 file changed

Lines changed: 1 addition & 3 deletions

File tree

‎block/bio.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -444,9 +444,7 @@ struct bio *bio_alloc_bioset(gfp_t gfp_mask, unsigned int nr_iovecs,
444444
if (nr_iovecs > UIO_MAXIOV)
445445
return NULL;
446446

447-
p = kmalloc(sizeof(struct bio) +
448-
nr_iovecs * sizeof(struct bio_vec),
449-
gfp_mask);
447+
p = kmalloc(struct_size(bio, bi_inline_vecs, nr_iovecs), gfp_mask);
450448
front_pad = 0;
451449
inline_vecs = nr_iovecs;
452450
} else {

0 commit comments

Comments
 (0)