Skip to content

Commit

Permalink
blk-iocost: Use struct_size() in kzalloc_node()
Browse files Browse the repository at this point in the history
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 <[email protected]>
Addresses-KSPP-ID: KSPP#83
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
GustavoARSilva authored and axboe committed Jun 24, 2020
1 parent 1f4fe21 commit f61d6e2
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions block/blk-iocost.c
Original file line number Diff line number Diff line change
Expand Up @@ -2045,8 +2045,7 @@ static struct blkg_policy_data *ioc_pd_alloc(gfp_t gfp, struct request_queue *q,
int levels = blkcg->css.cgroup->level + 1;
struct ioc_gq *iocg;

iocg = kzalloc_node(sizeof(*iocg) + levels * sizeof(iocg->ancestors[0]),
gfp, q->node);
iocg = kzalloc_node(struct_size(iocg, ancestors, levels), gfp, q->node);
if (!iocg)
return NULL;

Expand Down

0 comments on commit f61d6e2

Please sign in to comment.