[PATCH 08/10] EDAC/altera: Skip ECC memory init if already initialized

Dinh Nguyen <[email protected]> Mon, 27 Jul 2026 08:24:14 -0500
Newsgroups org.kernel.vger.linux-edac,org.kernel.vger.linux-kernel,org.kernel.vger.stable
Message-ID <[email protected]>
altr_init_memory_port() unconditionally triggered the HW memory-init
block, which clears the entire memory and ECC data. On a re-probe (e.g.
a probe deferred via -EPROBE_DEFER that only succeeds after the
protected peripheral is active, or a rebind) this would wipe live
peripheral memory. Skip the destructive init when the INITCOMPLETE
status bit is already set, so it runs only once.

Assisted-by: Cursor:claude-4.8-opus
Fixes: 1166fde93d5b ("EDAC, altera: Add Arria10 ECC memory init functions")
Cc: [email protected]
Signed-off-by: Dinh Nguyen <[email protected]>
---
 drivers/edac/altera_edac.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/edac/altera_edac.c b/drivers/edac/altera_edac.c
index d8d2adc9c39ac..5087aa5ae5612 100644
--- a/drivers/edac/altera_edac.c
+++ b/drivers/edac/altera_edac.c
@@ -930,6 +930,18 @@ static int __maybe_unused altr_init_memory_port(void __iomem *ioaddr, int port)
 		clear_mask = ALTR_A10_ECC_ERRPENA_MASK;
 	}
 
+	/*
+	 * The HW init block clears the entire memory and ECC data, so only
+	 * run it once. If initialization already completed (e.g. on an
+	 * earlier probe or in the bootloader), skip it so a re-probe caused
+	 * by deferred probing or a rebind does not wipe an active peripheral.
+	 */
+	if (ecc_test_bits(stat_mask, (ioaddr + ALTR_A10_ECC_INITSTAT_OFST))) {
+		/* Clear any pending ECC interrupts */
+		writel(clear_mask, (ioaddr + ALTR_A10_ECC_INTSTAT_OFST));
+		return 0;
+	}
+
 	ecc_set_bits(init_mask, (ioaddr + ALTR_A10_ECC_CTRL_OFST));
 	while (limit--) {
 		if (ecc_test_bits(stat_mask,
-- 
2.42.0.411.g813d9a9188