Am 09.08.25 um 03:04 schrieb Mikhail Kshevetskiy:
> This makes code closer to linux driver.

Nitpick suggestion for subject and commit message:

###
mtd: spinand: Align logic for enabling ECC to match Linux kernel

This aligns the logic to match the Linux kernel implementation.
###

Anyways, this is also good as-is:

Reviewed-by: Frieder Schrempf <frieder.schre...@kontron.de>

> 
> Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevets...@iopsys.eu>
> ---
>  drivers/mtd/nand/spi/core.c | 24 +++++++++++++++---------
>  1 file changed, 15 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
> index c16d3954245..098ed0c4cd2 100644
> --- a/drivers/mtd/nand/spi/core.c
> +++ b/drivers/mtd/nand/spi/core.c
> @@ -530,12 +530,12 @@ static int spinand_mtd_read(struct mtd_info *mtd, 
> loff_t from,
>       struct nand_device *nand = mtd_to_nanddev(mtd);
>       unsigned int max_bitflips = 0;
>       struct nand_io_iter iter;
> -     bool enable_ecc = false;
> +     bool disable_ecc = false;
>       bool ecc_failed = false;
>       int ret = 0;
>  
> -     if (ops->mode != MTD_OPS_RAW && spinand->eccinfo.ooblayout)
> -             enable_ecc = true;
> +     if (ops->mode == MTD_OPS_RAW || !spinand->eccinfo.ooblayout)
> +             disable_ecc = true;
>  
>  #ifndef __UBOOT__
>       mutex_lock(&spinand->lock);
> @@ -543,15 +543,18 @@ static int spinand_mtd_read(struct mtd_info *mtd, 
> loff_t from,
>  
>       nanddev_io_for_each_page(nand, NAND_PAGE_READ, from, ops, &iter) {
>               schedule();
> +             if (disable_ecc)
> +                     iter.req.mode = MTD_OPS_RAW;
> +
>               ret = spinand_select_target(spinand, iter.req.pos.target);
>               if (ret)
>                       break;
>  
> -             ret = spinand_ecc_enable(spinand, enable_ecc);
> +             ret = spinand_ecc_enable(spinand, !disable_ecc);
>               if (ret)
>                       break;
>  
> -             ret = spinand_read_page(spinand, &iter.req, enable_ecc);
> +             ret = spinand_read_page(spinand, &iter.req, !disable_ecc);
>               if (ret < 0 && ret != -EBADMSG)
>                       break;
>  
> @@ -583,11 +586,11 @@ static int spinand_mtd_write(struct mtd_info *mtd, 
> loff_t to,
>       struct spinand_device *spinand = mtd_to_spinand(mtd);
>       struct nand_device *nand = mtd_to_nanddev(mtd);
>       struct nand_io_iter iter;
> -     bool enable_ecc = false;
> +     bool disable_ecc = false;
>       int ret = 0;
>  
> -     if (ops->mode != MTD_OPS_RAW && mtd->ooblayout)
> -             enable_ecc = true;
> +     if (ops->mode == MTD_OPS_RAW || !mtd->ooblayout)
> +             disable_ecc = true;
>  
>  #ifndef __UBOOT__
>       mutex_lock(&spinand->lock);
> @@ -595,11 +598,14 @@ static int spinand_mtd_write(struct mtd_info *mtd, 
> loff_t to,
>  
>       nanddev_io_for_each_page(nand, NAND_PAGE_WRITE, to, ops, &iter) {
>               schedule();
> +             if (disable_ecc)
> +                     iter.req.mode = MTD_OPS_RAW;
> +
>               ret = spinand_select_target(spinand, iter.req.pos.target);
>               if (ret)
>                       break;
>  
> -             ret = spinand_ecc_enable(spinand, enable_ecc);
> +             ret = spinand_ecc_enable(spinand, !disable_ecc);
>               if (ret)
>                       break;
>  

Reply via email to