Skip to content

Commit 3724ace

Browse files
Robert Richtersuryasaimadhu
authored andcommitted
EDAC/mc: Fix grain_bits calculation
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 <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Cc: "[email protected]" <[email protected]> Cc: James Morse <[email protected]> Cc: Mauro Carvalho Chehab <[email protected]> Cc: Tony Luck <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 3123c5c commit 3724ace

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

drivers/edac/edac_mc.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,9 +1235,13 @@ void edac_mc_handle_error(const enum hw_event_mc_err_type type,
12351235
if (p > e->location)
12361236
*(p - 1) = '\0';
12371237

1238-
/* Report the error via the trace interface */
1239-
grain_bits = fls_long(e->grain) + 1;
1238+
/* Sanity-check driver-supplied grain value. */
1239+
if (WARN_ON_ONCE(!e->grain))
1240+
e->grain = 1;
1241+
1242+
grain_bits = fls_long(e->grain - 1);
12401243

1244+
/* Report the error via the trace interface */
12411245
if (IS_ENABLED(CONFIG_RAS))
12421246
trace_mc_event(type, e->msg, e->label, e->error_count,
12431247
mci->mc_idx, e->top_layer, e->mid_layer,

0 commit comments

Comments
 (0)