linux/drivers/infiniband
Gustavo A. R. Silva 7a7b0fea6f IB/srp: Use struct_size() in kzalloc()
One of the more common cases of allocation size calculations is finding the
size of a structure that has a zero-sized array at the end, along with memory
for some number of elements for that array. For example:

struct foo {
    int stuff;
    void *entry[];
};

instance = kzalloc(sizeof(struct foo) + sizeof(void *) * count, GFP_KERNEL);

Instead of leaving these open-coded and prone to type mistakes, we can now
use the new struct_size() helper:

instance = kzalloc(struct_size(instance, entry, count), GFP_KERNEL);

This code was detected with the help of Coccinelle.

Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
2019-01-08 15:46:59 -07:00
..
core IB/core: Use struct_size() in kzalloc() 2019-01-07 11:59:33 -07:00
hw RDMA/hns: Modify the pbl ba page size for hip08 2019-01-07 12:14:42 -07:00
sw IB/rxe: Reuse code which sets port state 2018-12-20 14:20:58 -07:00
ulp IB/srp: Use struct_size() in kzalloc() 2019-01-08 15:46:59 -07:00
Kconfig RDMA: Fix building with CONFIG_MMU=n 2018-10-03 16:01:03 -06:00
Makefile IB/rdmavt: Create module framework and handle driver registration 2016-03-10 20:37:04 -05:00