• Mauro Carvalho Chehab's avatar
    sb_edac: Avoid overflow errors at memory size calculation · 14a7213e
    Mauro Carvalho Chehab authored
    commit deb09dda upstream.
    
    Sandy bridge EDAC is calculating the memory size with overflow.
    Basically, the size field and the integer calculation is using 32 bits.
    More bits are needed, when the DIMM memories have high density.
    
    The net result is that memories are improperly reported there, when
    high-density DIMMs are used:
    
    EDAC DEBUG: in drivers/edac/sb_edac.c, line at 591: mc#0: channel 0, dimm 0, -16384 Mb (-4194304 pages) bank: 8, rank: 2, row: 0x10000, col: 0x800
    EDAC DEBUG: in drivers/edac/sb_edac.c, line at 591: mc#0: channel 1, dimm 0, -16384 Mb (-4194304 pages) bank: 8, rank: 2, row: 0x10000, col: 0x800
    
    As the number of pages value is handled at the EDAC core as unsigned
    ints, the driver shows the 16 GB memories at sysfs interface as 16760832
    MB! The fix is simple: calculate the number of pages as unsigned 64-bits
    integer.
    
    After the patch, the memory size (16 GB) is properly detected:
    
    EDAC DEBUG: in drivers/edac/sb_edac.c, line at 592: mc#0: channel 0, dimm 0, 16384 Mb (4194304 pages) bank: 8, rank: 2, row: 0x10000, col: 0x800
    EDAC DEBUG: in drivers/edac/sb_edac.c, line at 592: mc#0: channel 1, dimm 0, 16384 Mb (4194304 pages) bank: 8, rank: 2, row: 0x10000, col: 0x800
    Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
    [bwh: Backported to 3.2:
     - Adjust context
     - Debug log function is debugf0(), not edac_dbg()]
    Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
    Cc: Qiang Huang <h.huangqiang@huawei.com>
    Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    14a7213e
sb_edac.c 46.1 KB