aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab@redhat.com>2012-09-20 11:09:30 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2012-09-25 06:38:20 -0400
commitdeb09ddaff1435f72dd598d38f9b58354c68a5ec (patch)
tree9a014cae7a7f499513d92623d4325821da89263f
parentb70f833377fc80d7446218b36206e2e299fc6bfd (diff)
sb_edac: Avoid overflow errors at memory size calculation
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 Cc: stable@kernel.org Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r--drivers/edac/sb_edac.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/drivers/edac/sb_edac.c b/drivers/edac/sb_edac.c
index f3b1f9fafa4b..5715b7c2c517 100644
--- a/drivers/edac/sb_edac.c
+++ b/drivers/edac/sb_edac.c
@@ -513,7 +513,8 @@ static int get_dimm_config(struct mem_ctl_info *mci)
513{ 513{
514 struct sbridge_pvt *pvt = mci->pvt_info; 514 struct sbridge_pvt *pvt = mci->pvt_info;
515 struct dimm_info *dimm; 515 struct dimm_info *dimm;
516 int i, j, banks, ranks, rows, cols, size, npages; 516 unsigned i, j, banks, ranks, rows, cols, npages;
517 u64 size;
517 u32 reg; 518 u32 reg;
518 enum edac_type mode; 519 enum edac_type mode;
519 enum mem_type mtype; 520 enum mem_type mtype;
@@ -585,10 +586,10 @@ static int get_dimm_config(struct mem_ctl_info *mci)
585 cols = numcol(mtr); 586 cols = numcol(mtr);
586 587
587 /* DDR3 has 8 I/O banks */ 588 /* DDR3 has 8 I/O banks */
588 size = (rows * cols * banks * ranks) >> (20 - 3); 589 size = ((u64)rows * cols * banks * ranks) >> (20 - 3);
589 npages = MiB_TO_PAGES(size); 590 npages = MiB_TO_PAGES(size);
590 591
591 edac_dbg(0, "mc#%d: channel %d, dimm %d, %d Mb (%d pages) bank: %d, rank: %d, row: %#x, col: %#x\n", 592 edac_dbg(0, "mc#%d: channel %d, dimm %d, %Ld Mb (%d pages) bank: %d, rank: %d, row: %#x, col: %#x\n",
592 pvt->sbridge_dev->mc, i, j, 593 pvt->sbridge_dev->mc, i, j,
593 size, npages, 594 size, npages,
594 banks, ranks, rows, cols); 595 banks, ranks, rows, cols);