linux/drivers/infiniband/ulp/srp
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
..
ib_srp.c IB/srp: Use struct_size() in kzalloc() 2019-01-08 15:46:59 -07:00
ib_srp.h RDMA/srp: Add support for immediate data 2018-12-19 15:07:25 -05:00
Kbuild
Kconfig ib_srp: depend on INFINIBAND_ADDR_TRANS 2018-04-27 11:15:44 -04:00