• Gustavo A. R. Silva's avatar
    nvmet-fc: use zero-sized array and struct_size() in kzalloc() · 6b80f1d2
    Gustavo A. R. Silva authored
    Update the code to use a zero-sized array instead of a pointer in
    structure nvmet_fc_tgt_queue and use struct_size() in kzalloc().
    
    Notice that 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;
    	struct boo entry[];
    };
    
    instance = kzalloc(sizeof(struct foo) + sizeof(struct boo) * 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: default avatarGustavo A. R. Silva <gustavo@embeddedor.com>
    Reviewed-by: default avatarJames Smart <james.smart@broadcom.com>
    Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
    6b80f1d2
fc.c 67.3 KB