linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mtd: spinand: winbond|toshiba: Fix ecc_get_status
@ 2023-06-20 21:16 Olivier Maignial
  2023-06-22  7:47 ` Miquel Raynal
  0 siblings, 1 reply; 2+ messages in thread
From: Olivier Maignial @ 2023-06-20 21:16 UTC (permalink / raw)
  Cc: olivier.maignial, Olivier Maignial, Miquel Raynal,
	Richard Weinberger, Vignesh Raghavendra, Mikhail Kshevetskiy,
	Frieder Schrempf, linux-mtd, linux-kernel

Reading ECC status is failing in toshiba & winbond spi-nand drivers.

tx58cxgxsxraix_ecc_get_status() and w25n02kv_ecc_get_status()
functions are using on-stack buffers which are not suitable
for DMA needs of spi-mem.

Fix this by using the spi-mem operations dedicated buffer
spinand->scratchbuf

See
spinand->scratchbuf:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/linux/mtd/spinand.h?h=v6.3#n418
spi_mem_check_op():
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/spi/spi-mem.c?h=v6.3#n199

Signed-off-by: Olivier Maignial <olivier.maignial@hotmail.fr>
---
 drivers/mtd/nand/spi/toshiba.c | 4 ++--
 drivers/mtd/nand/spi/winbond.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/nand/spi/toshiba.c b/drivers/mtd/nand/spi/toshiba.c
index 7380b1ebaccd..a80427c13121 100644
--- a/drivers/mtd/nand/spi/toshiba.c
+++ b/drivers/mtd/nand/spi/toshiba.c
@@ -73,7 +73,7 @@ static int tx58cxgxsxraix_ecc_get_status(struct spinand_device *spinand,
 {
 	struct nand_device *nand = spinand_to_nand(spinand);
 	u8 mbf = 0;
-	struct spi_mem_op op = SPINAND_GET_FEATURE_OP(0x30, &mbf);
+	struct spi_mem_op op = SPINAND_GET_FEATURE_OP(0x30, spinand->scratchbuf);
 
 	switch (status & STATUS_ECC_MASK) {
 	case STATUS_ECC_NO_BITFLIPS:
@@ -92,7 +92,7 @@ static int tx58cxgxsxraix_ecc_get_status(struct spinand_device *spinand,
 		if (spi_mem_exec_op(spinand->spimem, &op))
 			return nanddev_get_ecc_conf(nand)->strength;
 
-		mbf >>= 4;
+		mbf = *(spinand->scratchbuf) >> 4;
 
 		if (WARN_ON(mbf > nanddev_get_ecc_conf(nand)->strength || !mbf))
 			return nanddev_get_ecc_conf(nand)->strength;
diff --git a/drivers/mtd/nand/spi/winbond.c b/drivers/mtd/nand/spi/winbond.c
index 3ad58cd284d8..f507e3759301 100644
--- a/drivers/mtd/nand/spi/winbond.c
+++ b/drivers/mtd/nand/spi/winbond.c
@@ -108,7 +108,7 @@ static int w25n02kv_ecc_get_status(struct spinand_device *spinand,
 {
 	struct nand_device *nand = spinand_to_nand(spinand);
 	u8 mbf = 0;
-	struct spi_mem_op op = SPINAND_GET_FEATURE_OP(0x30, &mbf);
+	struct spi_mem_op op = SPINAND_GET_FEATURE_OP(0x30, spinand->scratchbuf);
 
 	switch (status & STATUS_ECC_MASK) {
 	case STATUS_ECC_NO_BITFLIPS:
@@ -126,7 +126,7 @@ static int w25n02kv_ecc_get_status(struct spinand_device *spinand,
 		if (spi_mem_exec_op(spinand->spimem, &op))
 			return nanddev_get_ecc_conf(nand)->strength;
 
-		mbf >>= 4;
+		mbf = *(spinand->scratchbuf) >> 4;
 
 		if (WARN_ON(mbf > nanddev_get_ecc_conf(nand)->strength || !mbf))
 			return nanddev_get_ecc_conf(nand)->strength;
-- 
2.34.1


______________________________________________________
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] mtd: spinand: winbond|toshiba: Fix ecc_get_status
  2023-06-20 21:16 [PATCH] mtd: spinand: winbond|toshiba: Fix ecc_get_status Olivier Maignial
@ 2023-06-22  7:47 ` Miquel Raynal
  0 siblings, 0 replies; 2+ messages in thread
From: Miquel Raynal @ 2023-06-22  7:47 UTC (permalink / raw)
  To: Olivier Maignial
  Cc: olivier.maignial, Richard Weinberger, Vignesh Raghavendra,
	Mikhail Kshevetskiy, Frieder Schrempf, linux-mtd, linux-kernel

Hi Olivier,

olivier.maignial@hotmail.fr wrote on Tue, 20 Jun 2023 23:16:15 +0200:

> Reading ECC status is failing in toshiba & winbond spi-nand drivers.
> 
> tx58cxgxsxraix_ecc_get_status() and w25n02kv_ecc_get_status()
> functions are using on-stack buffers which are not suitable
> for DMA needs of spi-mem.
> 
> Fix this by using the spi-mem operations dedicated buffer
> spinand->scratchbuf

Missing period       .

> 
> See
> spinand->scratchbuf:
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/linux/mtd/spinand.h?h=v6.3#n418
> spi_mem_check_op():
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/spi/spi-mem.c?h=v6.3#n199

Could you add a Cc: stable and a Fixes tag? It might require to address
both drivers independently (in two different commits), this is not a
problem.

Otherwise LGTM!

Thanks,
Miquèl

> Signed-off-by: Olivier Maignial <olivier.maignial@hotmail.fr>
> ---
>  drivers/mtd/nand/spi/toshiba.c | 4 ++--
>  drivers/mtd/nand/spi/winbond.c | 4 ++--
>  2 files changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/mtd/nand/spi/toshiba.c b/drivers/mtd/nand/spi/toshiba.c
> index 7380b1ebaccd..a80427c13121 100644
> --- a/drivers/mtd/nand/spi/toshiba.c
> +++ b/drivers/mtd/nand/spi/toshiba.c
> @@ -73,7 +73,7 @@ static int tx58cxgxsxraix_ecc_get_status(struct spinand_device *spinand,
>  {
>  	struct nand_device *nand = spinand_to_nand(spinand);
>  	u8 mbf = 0;
> -	struct spi_mem_op op = SPINAND_GET_FEATURE_OP(0x30, &mbf);
> +	struct spi_mem_op op = SPINAND_GET_FEATURE_OP(0x30, spinand->scratchbuf);
>  
>  	switch (status & STATUS_ECC_MASK) {
>  	case STATUS_ECC_NO_BITFLIPS:
> @@ -92,7 +92,7 @@ static int tx58cxgxsxraix_ecc_get_status(struct spinand_device *spinand,
>  		if (spi_mem_exec_op(spinand->spimem, &op))
>  			return nanddev_get_ecc_conf(nand)->strength;
>  
> -		mbf >>= 4;
> +		mbf = *(spinand->scratchbuf) >> 4;
>  
>  		if (WARN_ON(mbf > nanddev_get_ecc_conf(nand)->strength || !mbf))
>  			return nanddev_get_ecc_conf(nand)->strength;
> diff --git a/drivers/mtd/nand/spi/winbond.c b/drivers/mtd/nand/spi/winbond.c
> index 3ad58cd284d8..f507e3759301 100644
> --- a/drivers/mtd/nand/spi/winbond.c
> +++ b/drivers/mtd/nand/spi/winbond.c
> @@ -108,7 +108,7 @@ static int w25n02kv_ecc_get_status(struct spinand_device *spinand,
>  {
>  	struct nand_device *nand = spinand_to_nand(spinand);
>  	u8 mbf = 0;
> -	struct spi_mem_op op = SPINAND_GET_FEATURE_OP(0x30, &mbf);
> +	struct spi_mem_op op = SPINAND_GET_FEATURE_OP(0x30, spinand->scratchbuf);
>  
>  	switch (status & STATUS_ECC_MASK) {
>  	case STATUS_ECC_NO_BITFLIPS:
> @@ -126,7 +126,7 @@ static int w25n02kv_ecc_get_status(struct spinand_device *spinand,
>  		if (spi_mem_exec_op(spinand->spimem, &op))
>  			return nanddev_get_ecc_conf(nand)->strength;
>  
> -		mbf >>= 4;
> +		mbf = *(spinand->scratchbuf) >> 4;
>  
>  		if (WARN_ON(mbf > nanddev_get_ecc_conf(nand)->strength || !mbf))
>  			return nanddev_get_ecc_conf(nand)->strength;


______________________________________________________
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:[~2023-06-22  7:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-20 21:16 [PATCH] mtd: spinand: winbond|toshiba: Fix ecc_get_status Olivier Maignial
2023-06-22  7:47 ` Miquel Raynal

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