• Gustavo A. R. Silva's avatar
    scsi: megaraid_sas: Use struct_size() helper · e58ed500
    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 MR_PD_CFG_SEQ_NUM_SYNC {
    	...
            struct MR_PD_CFG_SEQ seq[1];
    } __packed;
    
    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:
    
    sizeof(struct MR_PD_CFG_SEQ_NUM_SYNC) + (sizeof(struct MR_PD_CFG_SEQ) * (MAX_PHYSICAL_DEVICES - 1))
    
    with:
    
    struct_size(pd_sync, seq, MAX_PHYSICAL_DEVICES - 1)
    
    This code was detected with the help of Coccinelle.
    Signed-off-by: default avatarGustavo A. R. Silva <gustavo@embeddedor.com>
    Acked-by: default avatarSumit Saxena <sumit.saxena@broadcom.com>
    Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
    e58ed500
megaraid_sas_fusion.c 149 KB