[PATCH] mtd: rawnand: lpc32xx_slc: Fix Hamming initialization

Miquel Raynal miquel.raynal at bootlin.com
Mon Apr 12 16:59:56 BST 2021


Since the Hamming software ECC engine has been updated to become a
proper and independent ECC engine, it is now mandatory to initialize the
engine before using any one of his functions. Failing to do this will
generally produce a NULL pointer dereference on the non-allocated
buffers at runtime.

Fixes: 19b2ce184b9f ("mtd: nand: ecc-hamming: Stop using raw NAND structures")
Cc: stable at vger.kernel.org
Reported-by: Trevor Woerner <twoerner at gmail.com>
Signed-off-by: Miquel Raynal <miquel.raynal at bootlin.com>
---
 drivers/mtd/nand/raw/lpc32xx_slc.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/drivers/mtd/nand/raw/lpc32xx_slc.c b/drivers/mtd/nand/raw/lpc32xx_slc.c
index 6b7269cfb7d8..df3b4415438f 100644
--- a/drivers/mtd/nand/raw/lpc32xx_slc.c
+++ b/drivers/mtd/nand/raw/lpc32xx_slc.c
@@ -773,6 +773,7 @@ static int lpc32xx_nand_attach_chip(struct nand_chip *chip)
 {
 	struct mtd_info *mtd = nand_to_mtd(chip);
 	struct lpc32xx_nand_host *host = nand_get_controller_data(chip);
+	int ret;
 
 	if (chip->ecc.engine_type != NAND_ECC_ENGINE_TYPE_ON_HOST)
 		return 0;
@@ -805,6 +806,13 @@ static int lpc32xx_nand_attach_chip(struct nand_chip *chip)
 	chip->ecc.correct = rawnand_sw_hamming_correct;
 	chip->ecc.hwctl = lpc32xx_nand_ecc_enable;
 
+	ret = rawnand_sw_hamming_init(chip);
+	if (ret) {
+		dev_err(mtd->dev.parent,
+			"SW Hamming ECC initialization failed (%d)\n", ret);
+		return ret;
+	}
+
 	/*
 	 * Use a custom BBT marker setup for small page FLASH that
 	 * won't interfere with the ECC layout. Large and huge page
@@ -819,8 +827,14 @@ static int lpc32xx_nand_attach_chip(struct nand_chip *chip)
 	return 0;
 }
 
+static void lpc32xx_nand_detach_chip(struct nand_chip *chip)
+{
+	rawnand_sw_hamming_cleanup(chip);
+}
+
 static const struct nand_controller_ops lpc32xx_nand_controller_ops = {
 	.attach_chip = lpc32xx_nand_attach_chip,
+	.detach_chip = lpc32xx_nand_detach_chip,
 };
 
 /*
-- 
2.27.0




More information about the linux-mtd mailing list