Skip to content

Commit 9ec22ac

Browse files
Priyanka Singhbp3tk0v
authored andcommitted
EDAC/fsl_ddr: Fix bad bit shift operations
Fix undefined behavior caused by left-shifting a negative value in the expression: cap_high ^ (1 << (bad_data_bit - 32)) The variable bad_data_bit ranges from 0 to 63. When it is less than 32, bad_data_bit - 32 becomes negative, and left-shifting by a negative value in C is undefined behavior. Fix this by combining cap_high and cap_low into a 64-bit variable. [ bp: Massage commit message, simplify error bits handling. ] Fixes: ea2eb9a ("EDAC, fsl-ddr: Separate FSL DDR driver from MPC85xx") Signed-off-by: Priyanka Singh <[email protected]> Signed-off-by: Li Yang <[email protected]> Signed-off-by: Frank Li <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 5d9aeaa commit 9ec22ac

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

drivers/edac/fsl_ddr_edac.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -328,21 +328,25 @@ static void fsl_mc_check(struct mem_ctl_info *mci)
328328
* TODO: Add support for 32-bit wide buses
329329
*/
330330
if ((err_detect & DDR_EDE_SBE) && (bus_width == 64)) {
331+
u64 cap = (u64)cap_high << 32 | cap_low;
332+
u32 s = syndrome;
333+
331334
sbe_ecc_decode(cap_high, cap_low, syndrome,
332335
&bad_data_bit, &bad_ecc_bit);
333336

334-
if (bad_data_bit != -1)
335-
fsl_mc_printk(mci, KERN_ERR,
336-
"Faulty Data bit: %d\n", bad_data_bit);
337-
if (bad_ecc_bit != -1)
338-
fsl_mc_printk(mci, KERN_ERR,
339-
"Faulty ECC bit: %d\n", bad_ecc_bit);
337+
if (bad_data_bit >= 0) {
338+
fsl_mc_printk(mci, KERN_ERR, "Faulty Data bit: %d\n", bad_data_bit);
339+
cap ^= 1ULL << bad_data_bit;
340+
}
341+
342+
if (bad_ecc_bit >= 0) {
343+
fsl_mc_printk(mci, KERN_ERR, "Faulty ECC bit: %d\n", bad_ecc_bit);
344+
s ^= 1 << bad_ecc_bit;
345+
}
340346

341347
fsl_mc_printk(mci, KERN_ERR,
342348
"Expected Data / ECC:\t%#8.8x_%08x / %#2.2x\n",
343-
cap_high ^ (1 << (bad_data_bit - 32)),
344-
cap_low ^ (1 << bad_data_bit),
345-
syndrome ^ (1 << bad_ecc_bit));
349+
upper_32_bits(cap), lower_32_bits(cap), s);
346350
}
347351

348352
fsl_mc_printk(mci, KERN_ERR,

0 commit comments

Comments
 (0)