[PATCH] mtd: spinand: winbond|toshiba: Fix ecc_get_status

Miquel Raynal miquel.raynal at bootlin.com
Thu Jun 22 00:47:23 PDT 2023


Hi Olivier,

olivier.maignial at 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 at 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;




More information about the linux-mtd mailing list