• Damien Le Moal's avatar
    scsi: libsas: Introduce struct smp_disc_resp · c3752f44
    Damien Le Moal authored
    When compiling with gcc 12, several warnings are thrown by gcc when
    compiling drivers/scsi/libsas/sas_expander.c, e.g.:
    
    In function ‘sas_get_phy_change_count’,
        inlined from ‘sas_find_bcast_phy.constprop’ at
    drivers/scsi/libsas/sas_expander.c:1737:9:
    drivers/scsi/libsas/sas_expander.c:1697:39: warning: array subscript
    ‘struct smp_resp[0]’ is partly outside array bounds of ‘unsigned
    char[56]’ [-Warray-bounds]
     1697 |                 *pcc = disc_resp->disc.change_count;
          |                        ~~~~~~~~~~~~~~~^~~~~~~~~~~~~
    
    This is due to the use of the struct smp_resp to aggregate all possible
    response types using a union but allocating a response buffer with a size
    exactly equal to the size of the response type needed. This leads to access
    to fields of struct smp_resp from an allocated memory area that is smaller
    than the size of struct smp_resp.
    
    Fix this by defining struct smp_disc_resp for sas discovery operations.
    Since this structure and the generic struct smp_resp are identical for
    the little endian and big endian archs, move the definition of these
    structures at the end of include/scsi/sas.h to avoid repeating their
    definition.
    
    Link: https://lore.kernel.org/r/20220609022456.409087-2-damien.lemoal@opensource.wdc.comReviewed-by: default avatarJohn Garry <john.garry@huawei.com>
    Signed-off-by: default avatarDamien Le Moal <damien.lemoal@opensource.wdc.com>
    Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
    c3752f44
sas_expander.c 54.5 KB