From: Frank Li <Frank.Li@nxp.com>
To: York Sun <york.sun@nxp.com>, Borislav Petkov <bp@alien8.de>,
Tony Luck <tony.luck@intel.com>,
James Morse <james.morse@arm.com>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Robert Richter <rric@kernel.org>,
Krzysztof Kozlowski <krzk@kernel.org>,
Rob Herring <robh@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Shawn Guo <shawnguo@kernel.org>,
Sascha Hauer <s.hauer@pengutronix.de>,
Pengutronix Kernel Team <kernel@pengutronix.de>,
Fabio Estevam <festevam@gmail.com>
Cc: linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org,
Borislav Petkov <bp@suse.de>,
devicetree@vger.kernel.org, imx@lists.linux.dev,
linux-arm-kernel@lists.infradead.org,
Frank Li <Frank.Li@nxp.com>,
Priyanka Singh <priyanka.singh@nxp.com>,
Sherry Sun <sherry.sun@nxp.com>, Li Yang <leoyang.li@nxp.com>
Subject: [PATCH 3/6] EDAC: fsl: Fix bad bit shift operations
Date: Tue, 09 Jul 2024 16:23:04 -0400 [thread overview]
Message-ID: <20240709-imx95_edac-v1-3-3e9c146c1b01@nxp.com> (raw)
In-Reply-To: <20240709-imx95_edac-v1-0-3e9c146c1b01@nxp.com>
From: Priyanka Singh <priyanka.singh@nxp.com>
The original code:
cap_high ^ (1 << (bad_data_bit - 32))
The variable bad_data_bit ranges from 0 to 63. If bad_data_bit is below 32,
bad_data_bit - 32 will be a negative value. Left shifting a negative
value in C is undefined behavior.
Fix this by checking the range of bad_data_bit.
Fixes: ea2eb9a8b620 ("EDAC, fsl-ddr: Separate FSL DDR driver from MPC85xx")
Signed-off-by: Priyanka Singh <priyanka.singh@nxp.com>
Reviewed-by: Sherry Sun <sherry.sun@nxp.com>
Signed-off-by: Li Yang <leoyang.li@nxp.com>
Signed-off-by: Frank Li <Frank.Li@nxp.com>
---
drivers/edac/fsl_ddr_edac.c | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/drivers/edac/fsl_ddr_edac.c b/drivers/edac/fsl_ddr_edac.c
index 10b0a46669f3d..da743cf8a95e9 100644
--- a/drivers/edac/fsl_ddr_edac.c
+++ b/drivers/edac/fsl_ddr_edac.c
@@ -338,11 +338,18 @@ static void fsl_mc_check(struct mem_ctl_info *mci)
fsl_mc_printk(mci, KERN_ERR,
"Faulty ECC bit: %d\n", bad_ecc_bit);
- fsl_mc_printk(mci, KERN_ERR,
- "Expected Data / ECC:\t%#8.8x_%08x / %#2.2x\n",
- cap_high ^ (1 << (bad_data_bit - 32)),
- cap_low ^ (1 << bad_data_bit),
- syndrome ^ (1 << bad_ecc_bit));
+ if ((bad_data_bit > 0 && bad_data_bit < 32) && bad_ecc_bit > 0) {
+ fsl_mc_printk(mci, KERN_ERR,
+ "Expected Data / ECC:\t%#8.8x_%08x / %#2.2x\n",
+ cap_high, cap_low ^ (1 << bad_data_bit),
+ syndrome ^ (1 << bad_ecc_bit));
+ }
+ if (bad_data_bit >= 32 && bad_ecc_bit > 0) {
+ fsl_mc_printk(mci, KERN_ERR,
+ "Expected Data / ECC:\t%#8.8x_%08x / %#2.2x\n",
+ cap_high ^ (1 << (bad_data_bit - 32)),
+ cap_low, syndrome ^ (1 << bad_ecc_bit));
+ }
}
fsl_mc_printk(mci, KERN_ERR,
--
2.34.1
next prev parent reply other threads:[~2024-07-09 20:23 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-09 20:23 [PATCH 0/6] EDAC: fsl-ddr, add imx9 support Frank Li
2024-07-09 20:23 ` [PATCH 1/6] EDAC: fsl_ddr: Pass down fsl_mc_pdata in ddr_in32() and ddr_out32() Frank Li
2024-08-29 22:03 ` Frank Li
2024-10-10 15:33 ` Borislav Petkov
2024-10-10 16:07 ` Frank Li
2024-07-09 20:23 ` [PATCH 2/6] EDAC, fsl_ddr: Move global variable into struct fsl_mc_pdata Frank Li
2024-07-09 20:23 ` Frank Li [this message]
2024-07-09 20:23 ` [PATCH 4/6] dt-bindings: memory: fsl: Add compatible string nxp,imx9-memory-controller Frank Li
2024-07-10 6:49 ` Krzysztof Kozlowski
2024-07-10 7:18 ` [PATCH 4/6] dt-bindings: memory: fsl: Add compatible string nxp, imx9-memory-controller Alexander Stein
2024-07-12 3:27 ` Frank Li
2024-07-12 6:08 ` Alexander Stein
2024-07-09 20:23 ` [PATCH 5/6] EDAC: fsl_ddr: Add support for i.MX9 DDR controller Frank Li
2024-07-09 20:23 ` [PATCH 6/6] arm64: dts: imx93: add ddr edac support Frank Li
2024-07-10 2:25 ` Peng Fan
2024-07-10 14:38 ` Frank Li
2024-09-30 20:42 ` [PATCH 0/6] EDAC: fsl-ddr, add imx9 support Frank Li
2024-10-02 9:08 ` Borislav Petkov
2024-10-02 10:48 ` Krzysztof Kozlowski
2024-10-02 10:52 ` Krzysztof Kozlowski
2024-10-09 15:48 ` Frank Li
2024-10-09 16:20 ` Borislav Petkov
2024-10-09 18:31 ` Frank Li
2024-10-09 19:22 ` Borislav Petkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240709-imx95_edac-v1-3-3e9c146c1b01@nxp.com \
--to=frank.li@nxp.com \
--cc=bp@alien8.de \
--cc=bp@suse.de \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=festevam@gmail.com \
--cc=imx@lists.linux.dev \
--cc=james.morse@arm.com \
--cc=kernel@pengutronix.de \
--cc=krzk+dt@kernel.org \
--cc=krzk@kernel.org \
--cc=leoyang.li@nxp.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-edac@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=priyanka.singh@nxp.com \
--cc=robh@kernel.org \
--cc=rric@kernel.org \
--cc=s.hauer@pengutronix.de \
--cc=shawnguo@kernel.org \
--cc=sherry.sun@nxp.com \
--cc=tony.luck@intel.com \
--cc=york.sun@nxp.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).