• Gustavo A. R. Silva's avatar
    spi: Use struct_size() helper · aef97522
    Gustavo A. R. Silva authored
    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 spi_replaced_transfers {
    	...
            struct spi_transfer inserted_transfers[];
    };
    
    Make use of the struct_size() helper instead of an open-coded version
    in order to avoid any potential type mistakes.
    
    So, replace the following form:
    
    insert * sizeof(struct spi_transfer) + sizeof(struct spi_replaced_transfers)
    
    with:
    
    struct_size(rxfer, inserted_transfers, insert)
    
    This code was detected with the help of Coccinelle.
    Signed-off-by: default avatarGustavo A. R. Silva <gustavo@embeddedor.com>
    Signed-off-by: default avatarMark Brown <broonie@kernel.org>
    aef97522
spi.c 102 KB