From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1B78B606A31F for ; Sun, 6 Dec 2026 04:41:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=nKZ0siLJ; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=UVyyNjpf DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Unsubscribe-Post:List-Owner; bh=LVRSkwS9g8IXEuw0K6qz8OO/B5i8CvOdafMRqnTcMU8=; b=nKZ0siLJXwKtoc2fkSDEd3MI3w RACOnro3eVZu5YuerNca+cuHaB51KwutLQkMn7JV4UUXaf8QvBoQyx53sv22GEJywX1F0+mZDLAzn IFD1Rwu8fQit1JB+k6ziXZWMb0geYud98UG0jrq8/uR9mzXJUkqdu6XLj4E5T8XF5DSgLLTaiPWD6 tlhCNqM/sukhJcc8GW17SEDWUtKzmJdKEQDwPJe5Udacl4N/1AkCfzkeOVkO4aG15vek/SWydwg+c HsSAcDL3ICpFlo4RwHp4VijqQ0fSvzWARqjBcpY6bzCMxw98yZQFUC2WJO2Ip9+i5Df7Knuzgy85C R9tuJ70Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xa443-00000003EK1-0WjL; Sun, 06 Dec 2026 04:41:31 +0000 Received: from mail-pg1-x52d.google.com ([2607:f8b0:4864:20::52d]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xa440-00000003EJf-1ZCi for linux-mtd@lists.infradead.org; Sun, 06 Dec 2026 04:41:29 +0000 Received: by mail-pg1-x52d.google.com with SMTP id 41be03b00d2f7-cdb684859cbso1398777a12.1 for ; Sat, 05 Dec 2026 20:41:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796532086; x=1797136886; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=JugNEFPjpLfCw/k/+m1gM6UztUh+FGm3a9NYXi6N19U=; b=UVyyNjpfmps3HZLxWvwpky0tV/2u5GqciqAcnx8t5E8zTWE4sBBTFiJ+HWQTlN0Fww dDBD/8sroyx5HQUf1oZsHydzWfJG64Cqe4NCGyoZECk33TYHOr9fycneewGJvNGQoupT kIgABmqZaxH8sGWJrJuRPkzrlkKm9KXPAiaP9KelApqAp8cP3LJjc55nLmwwKZ+phnwa hjumamIDWpzvov5mPT79R6baX6m07n4OR4tZ3kscOFOaX5pNjA8D53KH9HIffJZSvLGI qLlAftXr9ONr2EpYbmRxlkXpizuJ/5Lf6YVoR0oHOC/IeLPg71mOBtnj0TAHcfKaac5h GSZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796532086; x=1797136886; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=JugNEFPjpLfCw/k/+m1gM6UztUh+FGm3a9NYXi6N19U=; b=ZJvQQLgBJFpbCAULy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8G1BU3VrGoKickQ3v/3hMOkoXdQhuyshPvCXnmksaOJyxxtOFTxfxU7gxESwp29Q FuhbwjON7Ske82FTawo+rN1gjnFN81bLhGuXgUwQVDSj1SEd/XgZ6SH3vzCxEjn9XThqzyvKAYc +A1cSEyfbjXz39k1IoOhNujx4= X-Received: by 2002:a05:6a20:da05:b0:3f9:7db7:735d with SMTP id adf61e73a8af0-41562b1641bmr7032388637.36.1796532086311; Sat, 05 Dec 2026 20:41:26 -0800 (PST) Received: from ryzen.lan ([2601:644:8000:37f::e34]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-ce13adac369sm754060a12.9.2026.12.05.20.41.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2026 20:41:24 -0800 (PST) From: Rosen Penev To: linux-mtd@lists.infradead.org Cc: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Boris Brezillon , stable@vger.kernel.org Subject: [PATCH] mtd: rawnand: ndfc: correct ECC errors in Smart Media byte order Date: Sat, 5 Dec 2026 20:41:22 -0800 Message-ID: <20261206044122.306763-1-rosenp@gmail.com> X-Mailer: git-send-email 2.56.1 X-Archived-By: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261205_204128_449343_9B124C89 X-CRM114-Status: GOOD ( 12.66 ) X-Spam-Score: -2.1 (--) X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-mtd" X-Spam-Status: No, score=-14.1 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 The NDFC calculates its ECC in Smart Media byte order, and since commit 418b2e56b8a6 ("[MTD] NAND: use SmartMedia ECC byte order for ndfc") the driver selects MTD_NAND_ECC_SMC (now MTD_NAND_ECC_SW_HAMMING_SMC) so the software Hamming code corrects errors in that order. Commit 309600c14e36 ("mtd: rawnand: Allow selection of ECC byte ordering at runtime") replaced the compile time option with the NAND_ECC_SOFT_HAMMING_SM_ORDER flag, but sets that flag only for the software ECC engine. The NDFC uses the on-host engine, so rawnand_sw_hamming_correct() has corrected its errors in the regular byte order since then. That swaps the two nibbles of the faulty byte address within each 256-byte step: a single bit error at byte 0x01 of a step is "corrected" by flipping the same bit at byte 0x10. The read succeeds and reports corrected bitflips, but the data now has two bad bits instead of one. UBI then scrubs the block and writes the damaged data back with a valid ECC. mtd_nandbiterrs on a Meraki MX60 (APM82181) shows it: mtd_nandbiterrs: Inserted biterror @ 1025/7 mtd_nandbiterrs: Read reported 4 corrected bit errors mtd_nandbiterrs: Error: page offset 1025, expected 80, got 00 mtd_nandbiterrs: Error: page offset 1040, expected 48, got c8 mtd_nandbiterrs: ECC failure, read data is incorrect despite read success Correct the errors in Smart Media byte order, as fsmc_nand does for its hardware engine. Fixes: 309600c14e36 ("mtd: rawnand: Allow selection of ECC byte ordering at runtime") Cc: stable@vger.kernel.org Signed-off-by: Rosen Penev --- drivers/mtd/nand/raw/ndfc.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/nand/raw/ndfc.c b/drivers/mtd/nand/raw/ndfc.c index d7b119028a71..0ebe23726e0c 100644 --- a/drivers/mtd/nand/raw/ndfc.c +++ b/drivers/mtd/nand/raw/ndfc.c @@ -18,6 +18,7 @@ */ #include #include +#include #include #include #include @@ -101,6 +102,14 @@ static int ndfc_calculate_ecc(struct nand_chip *chip, return 0; } +static int ndfc_correct_ecc(struct nand_chip *chip, u_char *buf, + u_char *read_ecc, u_char *calc_ecc) +{ + /* The ECC bytes come from ndfc_calculate_ecc() in SMC order */ + return ecc_sw_hamming_correct(buf, read_ecc, calc_ecc, + chip->ecc.size, true); +} + /* * Speedups for buffer read/write/verify * @@ -146,7 +155,7 @@ static int ndfc_chip_init(struct ndfc_controller *ndfc, chip->controller = &ndfc->ndfc_control; chip->legacy.read_buf = ndfc_read_buf; chip->legacy.write_buf = ndfc_write_buf; - chip->ecc.correct = rawnand_sw_hamming_correct; + chip->ecc.correct = ndfc_correct_ecc; chip->ecc.hwctl = ndfc_enable_hwecc; chip->ecc.calculate = ndfc_calculate_ecc; chip->ecc.engine_type = NAND_ECC_ENGINE_TYPE_ON_HOST; -- 2.56.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/