]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commit
EDAC/mc: Fix grain_bits calculation
authorRobert Richter <rrichter@marvell.com>
Mon, 24 Jun 2019 15:08:55 +0000 (15:08 +0000)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Wed, 16 Oct 2019 09:55:21 +0000 (11:55 +0200)
commit0d4b8c07cebacd4c48a26cad2032f43c3b328d60
tree7e6d9439bfbc1b45d09c5ba96f891fb7d3090b71
parent6e3b2218f2aee2002735f2b6a0b82bc819ca5de8
EDAC/mc: Fix grain_bits calculation

BugLink: https://bugs.launchpad.net/bugs/1847155
[ Upstream commit 3724ace582d9f675134985727fd5e9811f23c059 ]

The grain in EDAC is defined as "minimum granularity for an error
report, in bytes". The following calculation of the grain_bits in
edac_mc is wrong:

grain_bits = fls_long(e->grain) + 1;

Where grain_bits is defined as:

grain = 1 << grain_bits

Example:

grain = 8 # 64 bit (8 bytes)
grain_bits = fls_long(8) + 1
grain_bits = 4 + 1 = 5

grain = 1 << grain_bits
grain = 1 << 5 = 32

Replace it with the correct calculation:

grain_bits = fls_long(e->grain - 1);

The example gives now:

grain_bits = fls_long(8 - 1)
grain_bits = fls_long(7)
grain_bits = 3

grain = 1 << 3 = 8

Also, check if the hardware reports a reasonable grain != 0 and fallback
with a warning to 1 byte granularity otherwise.

 [ bp: massage a bit. ]

Signed-off-by: Robert Richter <rrichter@marvell.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: "linux-edac@vger.kernel.org" <linux-edac@vger.kernel.org>
Cc: James Morse <james.morse@arm.com>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>
Cc: Tony Luck <tony.luck@intel.com>
Link: https://lkml.kernel.org/r/20190624150758.6695-2-rrichter@marvell.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
drivers/edac/edac_mc.c