linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] mtd: rawnand: lpc32xx_slc: Fix external use of SW Hamming ECC helper
@ 2021-04-13  9:59 Miquel Raynal
  2021-04-13 12:51 ` Trevor Woerner
  0 siblings, 1 reply; 2+ messages in thread
From: Miquel Raynal @ 2021-04-13  9:59 UTC (permalink / raw)
  To: Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus, linux-mtd
  Cc: Miquel Raynal, stable, Trevor Woerner

Since the Hamming software ECC engine has been updated to become a
proper and independent ECC engine, it is now mandatory to either
initialize the engine before using any one of his functions or use one
of the bare helpers which only perform the calculations. As there is no
actual need for a proper ECC initialization, let's just use the bare
helper instead of the rawnand one.

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

diff --git a/drivers/mtd/nand/raw/lpc32xx_slc.c b/drivers/mtd/nand/raw/lpc32xx_slc.c
index 6b7269cfb7d8..65663f5ba54f 100644
--- a/drivers/mtd/nand/raw/lpc32xx_slc.c
+++ b/drivers/mtd/nand/raw/lpc32xx_slc.c
@@ -27,6 +27,7 @@
 #include <linux/of.h>
 #include <linux/of_gpio.h>
 #include <linux/mtd/lpc32xx_slc.h>
+#include <linux/mtd/nand-ecc-sw-hamming.h>
 
 #define LPC32XX_MODNAME		"lpc32xx-nand"
 
@@ -344,6 +345,18 @@ static int lpc32xx_nand_ecc_calculate(struct nand_chip *chip,
 	return 0;
 }
 
+/*
+ * Corrects the data
+ */
+static int lpc32xx_nand_ecc_correct(struct nand_chip *chip,
+				    unsigned char *buf,
+				    unsigned char *read_ecc,
+				    unsigned char *calc_ecc)
+{
+	return ecc_sw_hamming_correct(buf, read_ecc, calc_ecc,
+				      chip->ecc.size, false);
+}
+
 /*
  * Read a single byte from NAND device
  */
@@ -802,7 +815,7 @@ static int lpc32xx_nand_attach_chip(struct nand_chip *chip)
 	chip->ecc.write_oob = lpc32xx_nand_write_oob_syndrome;
 	chip->ecc.read_oob = lpc32xx_nand_read_oob_syndrome;
 	chip->ecc.calculate = lpc32xx_nand_ecc_calculate;
-	chip->ecc.correct = rawnand_sw_hamming_correct;
+	chip->ecc.correct = lpc32xx_nand_ecc_correct;
 	chip->ecc.hwctl = lpc32xx_nand_ecc_enable;
 
 	/*
@@ -819,8 +832,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


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] mtd: rawnand: lpc32xx_slc: Fix external use of SW Hamming ECC helper
  2021-04-13  9:59 [PATCH v2] mtd: rawnand: lpc32xx_slc: Fix external use of SW Hamming ECC helper Miquel Raynal
@ 2021-04-13 12:51 ` Trevor Woerner
  0 siblings, 0 replies; 2+ messages in thread
From: Trevor Woerner @ 2021-04-13 12:51 UTC (permalink / raw)
  To: Miquel Raynal
  Cc: Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
	linux-mtd, stable

On Tue 2021-04-13 @ 11:59:16 AM, Miquel Raynal wrote:
> Since the Hamming software ECC engine has been updated to become a
> proper and independent ECC engine, it is now mandatory to either
> initialize the engine before using any one of his functions or use one
> of the bare helpers which only perform the calculations. As there is no
> actual need for a proper ECC initialization, let's just use the bare
> helper instead of the rawnand one.
> 
> Fixes: 19b2ce184b9f ("mtd: nand: ecc-hamming: Stop using raw NAND structures")
> Cc: stable@vger.kernel.org
> Reported-by: Trevor Woerner <twoerner@gmail.com>
> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>

Tested-by: Trevor Woerner <twoerner@gmail.com>

> ---
>  drivers/mtd/nand/raw/lpc32xx_slc.c | 21 ++++++++++++++++++++-
>  1 file changed, 20 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/mtd/nand/raw/lpc32xx_slc.c b/drivers/mtd/nand/raw/lpc32xx_slc.c
> index 6b7269cfb7d8..65663f5ba54f 100644
> --- a/drivers/mtd/nand/raw/lpc32xx_slc.c
> +++ b/drivers/mtd/nand/raw/lpc32xx_slc.c
> @@ -27,6 +27,7 @@
>  #include <linux/of.h>
>  #include <linux/of_gpio.h>
>  #include <linux/mtd/lpc32xx_slc.h>
> +#include <linux/mtd/nand-ecc-sw-hamming.h>
>  
>  #define LPC32XX_MODNAME		"lpc32xx-nand"
>  
> @@ -344,6 +345,18 @@ static int lpc32xx_nand_ecc_calculate(struct nand_chip *chip,
>  	return 0;
>  }
>  
> +/*
> + * Corrects the data
> + */
> +static int lpc32xx_nand_ecc_correct(struct nand_chip *chip,
> +				    unsigned char *buf,
> +				    unsigned char *read_ecc,
> +				    unsigned char *calc_ecc)
> +{
> +	return ecc_sw_hamming_correct(buf, read_ecc, calc_ecc,
> +				      chip->ecc.size, false);
> +}
> +
>  /*
>   * Read a single byte from NAND device
>   */
> @@ -802,7 +815,7 @@ static int lpc32xx_nand_attach_chip(struct nand_chip *chip)
>  	chip->ecc.write_oob = lpc32xx_nand_write_oob_syndrome;
>  	chip->ecc.read_oob = lpc32xx_nand_read_oob_syndrome;
>  	chip->ecc.calculate = lpc32xx_nand_ecc_calculate;
> -	chip->ecc.correct = rawnand_sw_hamming_correct;
> +	chip->ecc.correct = lpc32xx_nand_ecc_correct;
>  	chip->ecc.hwctl = lpc32xx_nand_ecc_enable;
>  
>  	/*
> @@ -819,8 +832,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
> 

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-04-13 12:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-13  9:59 [PATCH v2] mtd: rawnand: lpc32xx_slc: Fix external use of SW Hamming ECC helper Miquel Raynal
2021-04-13 12:51 ` Trevor Woerner

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).