Skip to content

Commit 79da170

Browse files
committed
mtd: spi-nand: Isolate the MTD read logic in a helper
There is currently only a single path for performing page reads as requested by the MTD layer. Soon there will be two: - a "regular" page read - a continuous page read Let's extract the page read logic in a dedicated helper, so the introduction of continuous page reads will be as easy as checking whether continuous reads shall/can be used and calling one helper or the other. There is not behavioral change intended. Signed-off-by: Miquel Raynal <[email protected]> Link: https://lore.kernel.org/linux-mtd/[email protected]
1 parent 8adf1ac commit 79da170

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

drivers/mtd/nand/spi/core.c

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -630,25 +630,20 @@ static int spinand_write_page(struct spinand_device *spinand,
630630
return nand_ecc_finish_io_req(nand, (struct nand_page_io_req *)req);
631631
}
632632

633-
static int spinand_mtd_read(struct mtd_info *mtd, loff_t from,
634-
struct mtd_oob_ops *ops)
633+
static int spinand_mtd_regular_page_read(struct mtd_info *mtd, loff_t from,
634+
struct mtd_oob_ops *ops,
635+
unsigned int *max_bitflips)
635636
{
636637
struct spinand_device *spinand = mtd_to_spinand(mtd);
637638
struct nand_device *nand = mtd_to_nanddev(mtd);
638-
struct mtd_ecc_stats old_stats;
639-
unsigned int max_bitflips = 0;
640639
struct nand_io_iter iter;
641640
bool disable_ecc = false;
642641
bool ecc_failed = false;
643-
int ret = 0;
642+
int ret;
644643

645-
if (ops->mode == MTD_OPS_RAW || !spinand->eccinfo.ooblayout)
644+
if (ops->mode == MTD_OPS_RAW || !mtd->ooblayout)
646645
disable_ecc = true;
647646

648-
mutex_lock(&spinand->lock);
649-
650-
old_stats = mtd->ecc_stats;
651-
652647
nanddev_io_for_each_page(nand, NAND_PAGE_READ, from, ops, &iter) {
653648
if (disable_ecc)
654649
iter.req.mode = MTD_OPS_RAW;
@@ -664,13 +659,33 @@ static int spinand_mtd_read(struct mtd_info *mtd, loff_t from,
664659
if (ret == -EBADMSG)
665660
ecc_failed = true;
666661
else
667-
max_bitflips = max_t(unsigned int, max_bitflips, ret);
662+
*max_bitflips = max_t(unsigned int, *max_bitflips, ret);
668663

669664
ret = 0;
670665
ops->retlen += iter.req.datalen;
671666
ops->oobretlen += iter.req.ooblen;
672667
}
673668

669+
if (ecc_failed && !ret)
670+
ret = -EBADMSG;
671+
672+
return ret;
673+
}
674+
675+
static int spinand_mtd_read(struct mtd_info *mtd, loff_t from,
676+
struct mtd_oob_ops *ops)
677+
{
678+
struct spinand_device *spinand = mtd_to_spinand(mtd);
679+
struct mtd_ecc_stats old_stats;
680+
unsigned int max_bitflips = 0;
681+
int ret;
682+
683+
mutex_lock(&spinand->lock);
684+
685+
old_stats = mtd->ecc_stats;
686+
687+
ret = spinand_mtd_regular_page_read(mtd, from, ops, &max_bitflips);
688+
674689
if (ops->stats) {
675690
ops->stats->uncorrectable_errors +=
676691
mtd->ecc_stats.failed - old_stats.failed;
@@ -680,9 +695,6 @@ static int spinand_mtd_read(struct mtd_info *mtd, loff_t from,
680695

681696
mutex_unlock(&spinand->lock);
682697

683-
if (ecc_failed && !ret)
684-
ret = -EBADMSG;
685-
686698
return ret ? ret : max_bitflips;
687699
}
688700

0 commit comments

Comments
 (0)