From patchwork Fri Oct 11 15:31:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13832679 Received: from EUR03-VI1-obe.outbound.protection.outlook.com (mail-vi1eur03on2086.outbound.protection.outlook.com [40.107.103.86]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E10C5198A30 for ; Fri, 11 Oct 2024 15:32:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.103.86 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728660732; cv=fail; b=YgqzoaIiWOq5hY5ALxewwn4gwaFM1DfH1xb6C0pZaHG8wHrQqZ3Wi2sWQmcb0zrNjMHfULr3INgAIYi6jna5uA09ivEnhM0M4HhcRhNCpwNvXBIiy3NKw3NegI5yct/l01JECqe3N4BsDRtZlbFo+mE+j+/iyt4Vhk8HDKQ74xw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728660732; c=relaxed/simple; bh=hC0sBAxHzPnh9khLdTN4tfAoX1ZN08Fnf4NleRupY5U=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=EQVwgYYSJg5JUj0Ij4ABdNiMoV8cGOFuO4qevbxzdqYjgQ47QuSycBEM2vbfS0EVYpHVAAoj4HZK8YEOT4580ND7kUIG2fouTW8SbfJQojVeD+rTIzTre1F0Rgkw3F5cKLrDGGOwJu3shVjMUhVmRmpT/7DGV5CE7wgFYRELaOo= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=G0P0puEG; arc=fail smtp.client-ip=40.107.103.86 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="G0P0puEG" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=JLsMksbZ7ldFthLQgSBiinu453UTWNWDNGfUfR3GUuEOJ0BgpNJvnr5fTWskiQUjQYtIuVAU4D006lFQwn3S1fcvReitIyXR0AbyNTmlAJK+iYIJcKoB+TQ9QZj2ujzAuqUTBXNb/lanwRf2eXx65h1nXyynv1cbWICdLM/+KBhPbUe7pW5UaSFMNWtCnEpkF467H8EYhoduUiTMQdQwYsfalaI5CPGRQpPYZ7DypkFD5LqJ/b8J1gfVWX43Cq98cLYmGywcru900yLDLzxXRAXfCzjC0XXBWxI4bAm3DC8+JzckluR/uX8q1xd2wsSnwyvFduceMaVnqjrYqFhZdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=L1ERM/8wrAcld2CBubSctUu43sT3fAk/B7hSFIIETS4=; b=o+f/cSgD11bMsD8XzB/IXsuWxGldJZnt9zj/2fQkKW2uWj0mWBd/97DSrlcWzdTYSL1xE8Hy0PgI562ceKdoYP/4tTLCrAEFAjZlvFX5flCOLLl5AfoDXGgZUFXLqCQjn+Iv59RVwwBOhjP6jOCACMss+y8XDjFLRmxyrC6BdtcjpSpsHHfIdeSDStMQ1Ht3C9kzHtIRyevW01e9YRmw4yLebvchPtvBxrKDe2mRF00+Q8JEMIawtcLbK2ohmrA89euFvwvG4m1yjfkUBHWVcTicuBXGB+7VUTrB1FsS6LOpbpFMcavKoyCdJuoZD1N55H7xuhkfs2Q7OmTFdXXunw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=L1ERM/8wrAcld2CBubSctUu43sT3fAk/B7hSFIIETS4=; b=G0P0puEGzrIe3TKl0oNVtsIBYB3BnJYZzuVpU5MGDO23AR+U8qMvHrsRFGjGs2KGI0U8RfIrlzj20JSho4lRSiUAfyJr+Y+8aGW9jtGC5LluFrrinHGwG0myFMGFNdrPLPvbSTjE3aZxulwxgAghu12OCSfNW2nepdECOz5L2mnASwuaYy5YKKVlIPzLn9Yq2aBf2GSH2466pVNKIWp+mZze+cnF4xxQC5VMU5NSjfn0RsdSYY7+I5JSwHJUwumfr+mu6XU4OoB8IoAML+IzKE2aFPBYVlmV56BZa7TD7cLOHbasItb3kekYDHA0ea1m/T8nUVGprGdPxUsV3f7FnA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) by VE1PR04MB7360.eurprd04.prod.outlook.com (2603:10a6:800:1a3::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.23; Fri, 11 Oct 2024 15:32:06 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06%4]) with mapi id 15.20.8048.013; Fri, 11 Oct 2024 15:32:06 +0000 From: Frank Li Date: Fri, 11 Oct 2024 11:31:31 -0400 Subject: [PATCH v2 3/6] EDAC/fsl_ddr: Fix bad bit shift operations Message-Id: <20241011-imx95_edac-v2-3-011b68290951@nxp.com> References: <20241011-imx95_edac-v2-0-011b68290951@nxp.com> In-Reply-To: <20241011-imx95_edac-v2-0-011b68290951@nxp.com> To: York Sun , Borislav Petkov , Tony Luck , James Morse , Mauro Carvalho Chehab , Robert Richter , Krzysztof Kozlowski , Rob Herring , Conor Dooley , Krzysztof Kozlowski , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam Cc: linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org, Borislav Petkov , devicetree@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, Frank Li , Priyanka Singh , Sherry Sun , Li Yang X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=1728660703; l=1906; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=+xRnp+RgtbOKGy8sOPUGCuuHfdPE/AGGQkiNocVxHng=; b=SMO52SX0EcGfPBqBbXpSDQbbPJX77GVtYwAMuCSnjLrGcDJ/ZFR56hKvD8MaU9TYgbn5zZv6X SFvzBe7b28uClXDQP20eGC60xpABjgiLBoGg2PWiMggsbsRFik+ii9U X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: BY3PR04CA0014.namprd04.prod.outlook.com (2603:10b6:a03:217::19) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) Precedence: bulk X-Mailing-List: imx@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|VE1PR04MB7360:EE_ X-MS-Office365-Filtering-Correlation-Id: 81e99a82-bff9-4492-ba7d-08dcea09dcbd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|52116014|376014|366016|7416014|1800799024|921020|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?CyyCHkaJUXC1fTrgNN1EvLkJ7iilh6f?= =?utf-8?q?OAGkIpYp//0H5ugn/vdAlYoSB2DecKQLM4joZG6H28xFS0waD/BWLMBjB0xHXNxkL?= =?utf-8?q?RS8BhwMBOy2rt9tRyreCz2BrtbPmk++sxZmDoZJWn5mKIT7xIb1eZ1aJg1/3Kulf4?= =?utf-8?q?iyxjkMrdw2lOl7GFzOeL87gNYJ3wR6p+5ZYpmXjqT5QX2uH1EUs8IqhhEB+a06MT+?= =?utf-8?q?lURRoowObRCNfLDjHnBeP4fgxD5efRt6Tk7chBBzQahvEzLkNyu2K4N5/aAXa57qp?= =?utf-8?q?u5qR6YlNlwG/Y6hVbNzqY5O6guFs7dqkCtXcm+BZ6vLMpErksvN4EwU/lA4+ui9Tt?= =?utf-8?q?IkS16azYt8U7zO4fjm8JIdq7wSQx/GKUzto1gLkUhXHTFN7zcGXQ7jSoUMQWNKsI5?= =?utf-8?q?O9K3u8UURFdIXBUqN1bTrBGUQH1TRjhfQ0qv8ZKCM8CTxzoqc5H62UVnkwWFgPkvX?= =?utf-8?q?UwvPj2kemVPGqOBZoLr2CFBhbJ0EO0LGVwmKr64BE1N1nQmFlsaJu5ij5t5SqOmaG?= =?utf-8?q?R1EBnocNG46XDqW99SIRmCqA36cZKS7z5Ak6yEAM41Hj4g0n84D4yr4+KC9rjI+Dn?= =?utf-8?q?4gffcsiuFF0fflUmIDni0+G9uLNv/a6m1nD7OVCjABiVWsaUsozoiHnpq1/erSJc5?= =?utf-8?q?Q1XjG+6svBjRQG9AfAt7gwz3j6D8Y5GCDaZNrKD+lNpt3kGQeykrzGXbFONs9N8pY?= =?utf-8?q?wSIzLBa/pTbrPgedr4idxsh7dAXK7fGIZO+T94oPe6xV/bUhUwvBthyOQAPBkQJCm?= =?utf-8?q?EL988Lpyqyx/HjIYhQTlJz4dJKupMIdLVs1dxmEu3F1Spds9ownqYQspXKxBbSbmB?= =?utf-8?q?wGsOX7tNLUYwAg2bSyCTUFBcWhZNlvZEAyejAvEhAfGmGJd/5HbH1GmZppniaZdRq?= =?utf-8?q?HNDLQ9u9rnjI0OExR7Hx/hmwmjmhf/cH3KA6bntC57cslCa76DCErm1LD2bh6/248?= =?utf-8?q?O8Bw8hoYAc8wZvd/eeGWHNbQJjWzRAUEHHhNGtLQP/z/IOEzgAOP6L9Np1k2d+/4H?= =?utf-8?q?EzZ+E6+AZ3DJHHqe/ighjfi6UmKJEdNrhD3aO2h9nU9gKHIQlEv9ICYleBQd8wxyd?= =?utf-8?q?fxuecf1uuxD91/9qOMtElCqM7ZxbdzfScb+dCZtX4mNGXgsxMO5UWezN3sA+LvZtj?= =?utf-8?q?aqBH8bLG+8FdOjIvk4V+oYmrNVEzHKPrV2C4Wmc4aZB9VErgrxJbVNSEj3FxIz/4U?= =?utf-8?q?+8ZMweqdN+bjUOBKvRqdQQF4knlpV1EdgXTmvWMML1bcwgo7DJ3PlC0ebTJSF+Znj?= =?utf-8?q?IrPKcyRYqf7y5VegyPfAawWGVpLXniWZ5TNPnorEEo2l2BV05YwFkzc0=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB9642.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(52116014)(376014)(366016)(7416014)(1800799024)(921020)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?asobm2R2GQkOXsTAO1bU17KzURxs?= =?utf-8?q?vXvkLgnA+U5IiDsWozhBnW3IpjpPRAKpCP3g5Lg/Vb/oarL7PpFhsYK76YhllXD9F?= =?utf-8?q?+Js9wcpJCLvbvDIQsjqSq2Wt6SJjgvkcpaG2q2BUOgVIWRVFiFU6xsnXt1e5hPTjk?= =?utf-8?q?9hVce7W0t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6EF/Dwl/KdgIuP962M6ELOuHF+Qx0YRXUfDXgEQugzhWZs5CdtAAq8RMD7?= =?utf-8?q?A0aps086RErXG+i8FbWewJS3EfsnTJs4zT50AzJVEd0yQ7A3m6qMJU/jbx/2e4r8B?= =?utf-8?q?drMZd+6SbHpYJZzYBBc/3/MJVWhs0MjvRAB9y6EubBSzPbCc95gVMOsd6qz0OLjrU?= =?utf-8?q?HxgBQZbjGvcUftrwbZwEftQ9wEVaws+72cp0YFaxrJzLVZkc8IDjTXIpCtQmSBoq3?= =?utf-8?q?yV2ih9QhSb7tlv6Pcn9e3u6mfsker2VOO1QE48/V/CjbkS2+sH0ufc0+AmVh9/BUn?= =?utf-8?q?tGAU+yBzaXIAvEjgFeYVXufYC16pIF+8Dlv5eaqcYKY1M0g/OlUJApwzotwEpMOrC?= =?utf-8?q?KKtgJffMb0KcWGYsG8v9Wxt5tv8HowwMk6ByjMkNOiLUBnXB3UBREwbl9FGo7Knti?= =?utf-8?q?eiW0oCiNSfc8igdb7TivKsaQkXkul7YiqWIDG3T91pgOIXJ6hdAV34p6zLfqiHiOm?= =?utf-8?q?yEidZYv3WziJ?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 81e99a82-bff9-4492-ba7d-08dcea09dcbd X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2024 15:32:05.9771 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: lFKsWBLy1iZ/9aUtR2af6dxuthCUaNhrthmyWa/L7QZlUiFUxP6lxL5iv2GgygtHcsW/d1LOBMPm4eKIm4cFTg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB7360 From: Priyanka Singh 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 `bad_data_bit` 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 checking the range of `bad_data_bit` before performing the shift. Fixes: ea2eb9a8b620 ("EDAC, fsl-ddr: Separate FSL DDR driver from MPC85xx") Signed-off-by: Priyanka Singh Reviewed-by: Sherry Sun Signed-off-by: Li Yang Signed-off-by: Frank Li --- 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 7a9fb1202f1a0..ccc13c2adfd6f 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,