2016-11-04 10:42:59

by Masahiro Yamada

[permalink] [raw]
Subject: [PATCH 00/22] mtd: nand: return error code of nand_scan(_ident,_tail) on error


nand_scan(), nand_scan_ident(), nand_scan_tail() return
an appropriate negative value on error.

Most of drivers return the value from them on error,
but some of them return the fixed error code -ENXIO
(and a few return -ENODEV).

This series make those drivers return more precise error code.


Masahiro Yamada (22):
mtd: nand: ams-delta: return error code of nand_scan() on error
mtd: nand: cmx270: return error code of nand_scan() on error
mtd: nand: cs553x: return error code of nand_scan() on error
mtd: nand: gpio: return error code of nand_scan() on error
mtd: nand: mpc5121: return error code of nand_scan() on error
mtd: nand: tmio: return error code of nand_scan() on error
mtd: nand: orion: return error code of nand_scan() on error
mtd: nand: pasemi: return error code of nand_scan() on error
mtd: nand: plat_nand: return error code of nand_scan() on error
mtd: nand: atmel: return error code of nand_scan_ident/tail() on error
mtd: nand: brcmnand: return error code of nand_scan_ident/tail() on
error
mtd: nand: fsmc: return error code of nand_scan_ident/tail() on error
mtd: nand: lpc32xx: return error code of nand_scan_ident/tail() on
error
mtd: nand: mediatek: return error code of nand_scan_ident/tail() on
error
mtd: nand: mxc: return error code of nand_scan_ident/tail() on error
mtd: nand: omap2: return error code of nand_scan_ident/tail() on error
mtd: nand: vf610: return error code of nand_scan_ident/tail() on error
mtd: nand: cafe: return error code of nand_scan_ident() on error
mtd: nand: hisi504: return error code of nand_scan_ident() on error
mtd: nand: pxa3xx: return error code of nand_scan_ident() on error
mtd: nand: nandsim: remove unneeded checks for nand_scan_ident/tail()
mtd: nand: socrates: use nand_scan() for nand_scan_ident/tail() combo

drivers/mtd/nand/ams-delta.c | 5 ++---
drivers/mtd/nand/atmel_nand.c | 10 ++++------
drivers/mtd/nand/brcmnand/brcmnand.c | 10 ++++++----
drivers/mtd/nand/cafe_nand.c | 5 ++---
drivers/mtd/nand/cmx270_nand.c | 4 ++--
drivers/mtd/nand/cs553x_nand.c | 5 ++---
drivers/mtd/nand/fsmc_nand.c | 9 ++++-----
drivers/mtd/nand/gpio.c | 5 ++---
drivers/mtd/nand/hisi504_nand.c | 4 +---
drivers/mtd/nand/lpc32xx_mlc.c | 10 ++++------
drivers/mtd/nand/lpc32xx_slc.c | 9 +++------
drivers/mtd/nand/mpc5121_nfc.c | 4 ++--
drivers/mtd/nand/mtk_nand.c | 4 ++--
drivers/mtd/nand/mxc_nand.c | 10 ++++------
drivers/mtd/nand/nandsim.c | 4 ----
drivers/mtd/nand/omap2.c | 9 ++++-----
drivers/mtd/nand/orion_nand.c | 5 ++---
drivers/mtd/nand/pasemi_nand.c | 5 ++---
drivers/mtd/nand/plat_nand.c | 5 ++---
drivers/mtd/nand/pxa3xx_nand.c | 5 +++--
drivers/mtd/nand/socrates_nand.c | 12 ++----------
drivers/mtd/nand/tmio_nand.c | 6 +++---
drivers/mtd/nand/vf610_nfc.c | 10 ++++------
23 files changed, 62 insertions(+), 93 deletions(-)

--
1.9.1


2016-11-04 10:42:03

by Masahiro Yamada

[permalink] [raw]
Subject: [PATCH 18/22] mtd: nand: cafe: return error code of nand_scan_ident() on error

The nand_scan_ident() returns an appropriate error value when it
fails. Use it instead of the fixed error code -ENXIO.
(This driver is already doing so for nand_scan_tail().)

Signed-off-by: Masahiro Yamada <[email protected]>
---

drivers/mtd/nand/cafe_nand.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/nand/cafe_nand.c b/drivers/mtd/nand/cafe_nand.c
index 0b0c937..d40c32d 100644
--- a/drivers/mtd/nand/cafe_nand.c
+++ b/drivers/mtd/nand/cafe_nand.c
@@ -725,10 +725,9 @@ static int cafe_nand_probe(struct pci_dev *pdev,
usedma = 0;

/* Scan to find existence of the device */
- if (nand_scan_ident(mtd, 2, NULL)) {
- err = -ENXIO;
+ err = nand_scan_ident(mtd, 2, NULL);
+ if (err)
goto out_irq;
- }

cafe->dmabuf = dma_alloc_coherent(&cafe->pdev->dev,
2112 + sizeof(struct nand_buffers) +
--
1.9.1

2016-11-04 10:42:09

by Masahiro Yamada

[permalink] [raw]
Subject: [PATCH 20/22] mtd: nand: pxa3xx: return error code of nand_scan_ident() on error

The nand_scan_ident() returns an appropriate error value when it
fails. Use it instead of the fixed error code -ENODEV.
(This driver is already doing so for nand_scan_tail().)

Signed-off-by: Masahiro Yamada <[email protected]>
---

drivers/mtd/nand/pxa3xx_nand.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/nand/pxa3xx_nand.c b/drivers/mtd/nand/pxa3xx_nand.c
index b121bf4..06afa5f 100644
--- a/drivers/mtd/nand/pxa3xx_nand.c
+++ b/drivers/mtd/nand/pxa3xx_nand.c
@@ -1680,8 +1680,9 @@ static int pxa3xx_nand_scan(struct mtd_info *mtd)
chip->ecc.strength = pdata->ecc_strength;
chip->ecc.size = pdata->ecc_step_size;

- if (nand_scan_ident(mtd, 1, NULL))
- return -ENODEV;
+ ret = nand_scan_ident(mtd, 1, NULL);
+ if (ret)
+ return ret;

if (!pdata->keep_config) {
ret = pxa3xx_nand_init(host);
--
1.9.1

2016-11-04 10:42:26

by Masahiro Yamada

[permalink] [raw]
Subject: [PATCH 17/22] mtd: nand: vf610: return error code of nand_scan_ident/tail() on error

The nand_scan_ident/tail() returns an appropriate error value when
it fails. Use it instead of the fixed error code -ENXIO.

Signed-off-by: Masahiro Yamada <[email protected]>
---

drivers/mtd/nand/vf610_nfc.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/mtd/nand/vf610_nfc.c b/drivers/mtd/nand/vf610_nfc.c
index 3ad514c..3ea4bb1 100644
--- a/drivers/mtd/nand/vf610_nfc.c
+++ b/drivers/mtd/nand/vf610_nfc.c
@@ -717,10 +717,9 @@ static int vf610_nfc_probe(struct platform_device *pdev)
vf610_nfc_preinit_controller(nfc);

/* first scan to find the device and get the page size */
- if (nand_scan_ident(mtd, 1, NULL)) {
- err = -ENXIO;
+ err = nand_scan_ident(mtd, 1, NULL);
+ if (err)
goto error;
- }

vf610_nfc_init_controller(nfc);

@@ -775,10 +774,9 @@ static int vf610_nfc_probe(struct platform_device *pdev)
}

/* second phase scan */
- if (nand_scan_tail(mtd)) {
- err = -ENXIO;
+ err = nand_scan_tail(mtd);
+ if (err)
goto error;
- }

platform_set_drvdata(pdev, mtd);

--
1.9.1

2016-11-04 10:42:13

by Masahiro Yamada

[permalink] [raw]
Subject: [PATCH 03/22] mtd: nand: cs553x: return error code of nand_scan() on error

The nand_scan() returns an appropriate error value when it fails.
Use it instead of the fixed error code -ENXIO.

Signed-off-by: Masahiro Yamada <[email protected]>
---

drivers/mtd/nand/cs553x_nand.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/nand/cs553x_nand.c b/drivers/mtd/nand/cs553x_nand.c
index a65e4e0..594b286 100644
--- a/drivers/mtd/nand/cs553x_nand.c
+++ b/drivers/mtd/nand/cs553x_nand.c
@@ -242,10 +242,9 @@ static int __init cs553x_init_one(int cs, int mmio, unsigned long adr)
}

/* Scan to find existence of the device */
- if (nand_scan(new_mtd, 1)) {
- err = -ENXIO;
+ err = nand_scan(new_mtd, 1);
+ if (err)
goto out_free;
- }

cs553x_mtd[cs] = new_mtd;
goto out;
--
1.9.1

2016-11-04 10:42:16

by Masahiro Yamada

[permalink] [raw]
Subject: [PATCH 05/22] mtd: nand: mpc5121: return error code of nand_scan() on error

The nand_scan() returns an appropriate error value when it fails.
Use it instead of the fixed error code -ENXIO.

Signed-off-by: Masahiro Yamada <[email protected]>
---

drivers/mtd/nand/mpc5121_nfc.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/nand/mpc5121_nfc.c b/drivers/mtd/nand/mpc5121_nfc.c
index 7eacb2f..6d6eaed 100644
--- a/drivers/mtd/nand/mpc5121_nfc.c
+++ b/drivers/mtd/nand/mpc5121_nfc.c
@@ -777,9 +777,9 @@ static int mpc5121_nfc_probe(struct platform_device *op)
}

/* Detect NAND chips */
- if (nand_scan(mtd, be32_to_cpup(chips_no))) {
+ retval = nand_scan(mtd, be32_to_cpup(chips_no));
+ if (retval) {
dev_err(dev, "NAND Flash not found !\n");
- retval = -ENXIO;
goto error;
}

--
1.9.1

2016-11-04 10:42:33

by Masahiro Yamada

[permalink] [raw]
Subject: [PATCH 22/22] mtd: nand: socrates: use nand_scan() for nand_scan_ident/tail() combo

For this driver, there is nothing between nand_scan_ident() and
nand_scan_tail(). They can be merged into nand_scan().

Also, nand_scan() returns an appropriate error value when it fails.
Use it instead of the fixed error code -ENXIO.

Signed-off-by: Masahiro Yamada <[email protected]>
---

drivers/mtd/nand/socrates_nand.c | 12 ++----------
1 file changed, 2 insertions(+), 10 deletions(-)

diff --git a/drivers/mtd/nand/socrates_nand.c b/drivers/mtd/nand/socrates_nand.c
index 888fd31..72369bd 100644
--- a/drivers/mtd/nand/socrates_nand.c
+++ b/drivers/mtd/nand/socrates_nand.c
@@ -187,17 +187,9 @@ static int socrates_nand_probe(struct platform_device *ofdev)

dev_set_drvdata(&ofdev->dev, host);

- /* first scan to find the device and get the page size */
- if (nand_scan_ident(mtd, 1, NULL)) {
- res = -ENXIO;
+ res = nand_scan(mtd, 1);
+ if (res)
goto out;
- }
-
- /* second phase scan */
- if (nand_scan_tail(mtd)) {
- res = -ENXIO;
- goto out;
- }

res = mtd_device_register(mtd, NULL, 0);
if (!res)
--
1.9.1

2016-11-04 10:42:43

by Masahiro Yamada

[permalink] [raw]
Subject: [PATCH 13/22] mtd: nand: lpc32xx: return error code of nand_scan_ident/tail() on error

The nand_scan_ident/tail() returns an appropriate error value when
it fails. Use it instead of the fixed error code -ENXIO.

Signed-off-by: Masahiro Yamada <[email protected]>
---

drivers/mtd/nand/lpc32xx_mlc.c | 10 ++++------
drivers/mtd/nand/lpc32xx_slc.c | 9 +++------
2 files changed, 7 insertions(+), 12 deletions(-)

diff --git a/drivers/mtd/nand/lpc32xx_mlc.c b/drivers/mtd/nand/lpc32xx_mlc.c
index 8523881..5553a5d 100644
--- a/drivers/mtd/nand/lpc32xx_mlc.c
+++ b/drivers/mtd/nand/lpc32xx_mlc.c
@@ -747,10 +747,9 @@ static int lpc32xx_nand_probe(struct platform_device *pdev)
* Scan to find existance of the device and
* Get the type of NAND device SMALL block or LARGE block
*/
- if (nand_scan_ident(mtd, 1, NULL)) {
- res = -ENXIO;
+ res = nand_scan_ident(mtd, 1, NULL);
+ if (res)
goto err_exit3;
- }

host->dma_buf = devm_kzalloc(&pdev->dev, mtd->writesize, GFP_KERNEL);
if (!host->dma_buf) {
@@ -793,10 +792,9 @@ static int lpc32xx_nand_probe(struct platform_device *pdev)
* Fills out all the uninitialized function pointers with the defaults
* And scans for a bad block table if appropriate.
*/
- if (nand_scan_tail(mtd)) {
- res = -ENXIO;
+ res = nand_scan_tail(mtd);
+ if (res)
goto err_exit4;
- }

mtd->name = DRV_NAME;

diff --git a/drivers/mtd/nand/lpc32xx_slc.c b/drivers/mtd/nand/lpc32xx_slc.c
index 8d3edc3..f1094e5 100644
--- a/drivers/mtd/nand/lpc32xx_slc.c
+++ b/drivers/mtd/nand/lpc32xx_slc.c
@@ -894,10 +894,9 @@ static int lpc32xx_nand_probe(struct platform_device *pdev)
}

/* Find NAND device */
- if (nand_scan_ident(mtd, 1, NULL)) {
- res = -ENXIO;
+ res = nand_scan_ident(mtd, 1, NULL);
+ if (res)
goto err_exit3;
- }

/* OOB and ECC CPU and DMA work areas */
host->ecc_buf = (uint32_t *)(host->data_buf + LPC32XX_DMA_DATA_SIZE);
@@ -929,10 +928,8 @@ static int lpc32xx_nand_probe(struct platform_device *pdev)
/*
* Fills out all the uninitialized function pointers with the defaults
*/
- if (nand_scan_tail(mtd)) {
- res = -ENXIO;
+ res = nand_scan_tail(mtd);
goto err_exit3;
- }

mtd->name = "nxp_lpc3220_slc";
res = mtd_device_register(mtd, host->ncfg->parts,
--
1.9.1

2016-11-04 10:42:38

by Masahiro Yamada

[permalink] [raw]
Subject: [PATCH 19/22] mtd: nand: hisi504: return error code of nand_scan_ident() on error

The nand_scan_ident() returns an appropriate error value when it
fails. Use it instead of the fixed error code -ENODEV.
(This driver is already doing so for nand_scan_tail().)

Signed-off-by: Masahiro Yamada <[email protected]>
---

drivers/mtd/nand/hisi504_nand.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/mtd/nand/hisi504_nand.c b/drivers/mtd/nand/hisi504_nand.c
index 9432546..e40364e 100644
--- a/drivers/mtd/nand/hisi504_nand.c
+++ b/drivers/mtd/nand/hisi504_nand.c
@@ -774,10 +774,8 @@ static int hisi_nfc_probe(struct platform_device *pdev)
}

ret = nand_scan_ident(mtd, max_chips, NULL);
- if (ret) {
- ret = -ENODEV;
+ if (ret)
goto err_res;
- }

host->buffer = dmam_alloc_coherent(dev, mtd->writesize + mtd->oobsize,
&host->dma_buffer, GFP_KERNEL);
--
1.9.1

2016-11-04 10:42:31

by Masahiro Yamada

[permalink] [raw]
Subject: [PATCH 21/22] mtd: nand: nandsim: remove unneeded checks for nand_scan_ident/tail()

The nand_scan_ident/tail() never returns a positive value when it
fails.

Signed-off-by: Masahiro Yamada <[email protected]>
---

drivers/mtd/nand/nandsim.c | 4 ----
1 file changed, 4 deletions(-)

diff --git a/drivers/mtd/nand/nandsim.c b/drivers/mtd/nand/nandsim.c
index 1eb9344..c76287a 100644
--- a/drivers/mtd/nand/nandsim.c
+++ b/drivers/mtd/nand/nandsim.c
@@ -2313,8 +2313,6 @@ static int __init ns_init_module(void)
retval = nand_scan_ident(nsmtd, 1, NULL);
if (retval) {
NS_ERR("cannot scan NAND Simulator device\n");
- if (retval > 0)
- retval = -ENXIO;
goto error;
}

@@ -2350,8 +2348,6 @@ static int __init ns_init_module(void)
retval = nand_scan_tail(nsmtd);
if (retval) {
NS_ERR("can't register NAND Simulator\n");
- if (retval > 0)
- retval = -ENXIO;
goto error;
}

--
1.9.1

2016-11-04 10:43:25

by Masahiro Yamada

[permalink] [raw]
Subject: [PATCH 11/22] mtd: nand: brcmnand: return error code of nand_scan_ident/tail() on error

The nand_scan_ident/tail() returns an appropriate error value when
it fails. Use it instead of the fixed error code -ENXIO.

Signed-off-by: Masahiro Yamada <[email protected]>
---

drivers/mtd/nand/brcmnand/brcmnand.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/nand/brcmnand/brcmnand.c b/drivers/mtd/nand/brcmnand/brcmnand.c
index 9d2424b..42ebd73 100644
--- a/drivers/mtd/nand/brcmnand/brcmnand.c
+++ b/drivers/mtd/nand/brcmnand/brcmnand.c
@@ -2209,8 +2209,9 @@ static int brcmnand_init_cs(struct brcmnand_host *host, struct device_node *dn)
nand_writereg(ctrl, cfg_offs,
nand_readreg(ctrl, cfg_offs) & ~CFG_BUS_WIDTH);

- if (nand_scan_ident(mtd, 1, NULL))
- return -ENXIO;
+ ret = nand_scan_ident(mtd, 1, NULL);
+ if (ret)
+ return ret;

chip->options |= NAND_NO_SUBPAGE_WRITE;
/*
@@ -2234,8 +2235,9 @@ static int brcmnand_init_cs(struct brcmnand_host *host, struct device_node *dn)
if (ret)
return ret;

- if (nand_scan_tail(mtd))
- return -ENXIO;
+ ret = nand_scan_tail(mtd);
+ if (ret)
+ return ret;

return mtd_device_register(mtd, NULL, 0);
}
--
1.9.1

2016-11-04 10:42:24

by Masahiro Yamada

[permalink] [raw]
Subject: [PATCH 10/22] mtd: nand: atmel: return error code of nand_scan_ident/tail() on error

The nand_scan_ident/tail() returns an appropriate error value when
it fails. Use it instead of the fixed error code -ENXIO.

Signed-off-by: Masahiro Yamada <[email protected]>
---

drivers/mtd/nand/atmel_nand.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
index 68b9160..9ebd5ec 100644
--- a/drivers/mtd/nand/atmel_nand.c
+++ b/drivers/mtd/nand/atmel_nand.c
@@ -2267,10 +2267,9 @@ static int atmel_nand_probe(struct platform_device *pdev)
dev_info(host->dev, "No DMA support for NAND access.\n");

/* first scan to find the device and get the page size */
- if (nand_scan_ident(mtd, 1, NULL)) {
- res = -ENXIO;
+ res = nand_scan_ident(mtd, 1, NULL);
+ if (res)
goto err_scan_ident;
- }

if (host->board.on_flash_bbt || on_flash_bbt)
nand_chip->bbt_options |= NAND_BBT_USE_FLASH;
@@ -2304,10 +2303,9 @@ static int atmel_nand_probe(struct platform_device *pdev)
}

/* second phase scan */
- if (nand_scan_tail(mtd)) {
- res = -ENXIO;
+ res = nand_scan_tail(mtd);
+ if (res)
goto err_scan_tail;
- }

mtd->name = "atmel_nand";
res = mtd_device_register(mtd, host->board.parts,
--
1.9.1

2016-11-04 10:43:52

by Masahiro Yamada

[permalink] [raw]
Subject: [PATCH 08/22] mtd: nand: pasemi: return error code of nand_scan() on error

The nand_scan() returns an appropriate error value when it fails.
Use it instead of the fixed error code -ENXIO.

Signed-off-by: Masahiro Yamada <[email protected]>
---

drivers/mtd/nand/pasemi_nand.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/nand/pasemi_nand.c b/drivers/mtd/nand/pasemi_nand.c
index 5de7591..074b8b0 100644
--- a/drivers/mtd/nand/pasemi_nand.c
+++ b/drivers/mtd/nand/pasemi_nand.c
@@ -156,10 +156,9 @@ static int pasemi_nand_probe(struct platform_device *ofdev)
chip->bbt_options = NAND_BBT_USE_FLASH;

/* Scan to find existence of the device */
- if (nand_scan(pasemi_nand_mtd, 1)) {
- err = -ENXIO;
+ err = nand_scan(pasemi_nand_mtd, 1);
+ if (err)
goto out_lpc;
- }

if (mtd_device_register(pasemi_nand_mtd, NULL, 0)) {
dev_err(dev, "Unable to register MTD device\n");
--
1.9.1

2016-11-04 10:42:20

by Masahiro Yamada

[permalink] [raw]
Subject: [PATCH 14/22] mtd: nand: mediatek: return error code of nand_scan_ident/tail() on error

The nand_scan_ident/tail() returns an appropriate error value when
it fails. Use it instead of the fixed error code -ENODEV.

Signed-off-by: Masahiro Yamada <[email protected]>
---

drivers/mtd/nand/mtk_nand.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/nand/mtk_nand.c b/drivers/mtd/nand/mtk_nand.c
index 5223a21..6c3eed3 100644
--- a/drivers/mtd/nand/mtk_nand.c
+++ b/drivers/mtd/nand/mtk_nand.c
@@ -1297,7 +1297,7 @@ static int mtk_nfc_nand_chip_init(struct device *dev, struct mtk_nfc *nfc,

ret = nand_scan_ident(mtd, nsels, NULL);
if (ret)
- return -ENODEV;
+ return ret;

/* store bbt magic in page, cause OOB is not protected */
if (nand->bbt_options & NAND_BBT_USE_FLASH)
@@ -1323,7 +1323,7 @@ static int mtk_nfc_nand_chip_init(struct device *dev, struct mtk_nfc *nfc,

ret = nand_scan_tail(mtd);
if (ret)
- return -ENODEV;
+ return ret;

ret = mtd_device_parse_register(mtd, NULL, NULL, NULL, 0);
if (ret) {
--
1.9.1

2016-11-04 10:44:24

by Masahiro Yamada

[permalink] [raw]
Subject: [PATCH 02/22] mtd: nand: cmx270: return error code of nand_scan() on error

The nand_scan() returns an appropriate error value when it fails.
Use it instead of the fixed error code -ENXIO.

Signed-off-by: Masahiro Yamada <[email protected]>
---

drivers/mtd/nand/cmx270_nand.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/nand/cmx270_nand.c b/drivers/mtd/nand/cmx270_nand.c
index 4913378..226ac0b 100644
--- a/drivers/mtd/nand/cmx270_nand.c
+++ b/drivers/mtd/nand/cmx270_nand.c
@@ -195,9 +195,9 @@ static int __init cmx270_init(void)
this->write_buf = cmx270_write_buf;

/* Scan to find existence of the device */
- if (nand_scan (cmx270_nand_mtd, 1)) {
+ ret = nand_scan(cmx270_nand_mtd, 1);
+ if (ret) {
pr_notice("No NAND device\n");
- ret = -ENXIO;
goto err_scan;
}

--
1.9.1

2016-11-04 10:42:14

by Masahiro Yamada

[permalink] [raw]
Subject: [PATCH 04/22] mtd: nand: gpio: return error code of nand_scan() on error

The nand_scan() returns an appropriate error value when it fails.
Use it instead of the fixed error code -ENXIO.

Signed-off-by: Masahiro Yamada <[email protected]>
---

drivers/mtd/nand/gpio.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/nand/gpio.c b/drivers/mtd/nand/gpio.c
index 6317f68..0d24857 100644
--- a/drivers/mtd/nand/gpio.c
+++ b/drivers/mtd/nand/gpio.c
@@ -286,10 +286,9 @@ static int gpio_nand_probe(struct platform_device *pdev)
if (gpio_is_valid(gpiomtd->plat.gpio_nwp))
gpio_direction_output(gpiomtd->plat.gpio_nwp, 1);

- if (nand_scan(mtd, 1)) {
- ret = -ENXIO;
+ ret = nand_scan(mtd, 1);
+ if (ret)
goto err_wp;
- }

if (gpiomtd->plat.adjust_parts)
gpiomtd->plat.adjust_parts(&gpiomtd->plat, mtd->size);
--
1.9.1

2016-11-04 10:45:07

by Masahiro Yamada

[permalink] [raw]
Subject: [PATCH 06/22] mtd: nand: tmio: return error code of nand_scan() on error

The nand_scan() returns an appropriate error value when it fails.
Use it instead of the fixed error code -ENODEV.

Signed-off-by: Masahiro Yamada <[email protected]>
---

drivers/mtd/nand/tmio_nand.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/nand/tmio_nand.c b/drivers/mtd/nand/tmio_nand.c
index 08b3054..fc5e773 100644
--- a/drivers/mtd/nand/tmio_nand.c
+++ b/drivers/mtd/nand/tmio_nand.c
@@ -435,10 +435,10 @@ static int tmio_probe(struct platform_device *dev)
nand_chip->waitfunc = tmio_nand_wait;

/* Scan to find existence of the device */
- if (nand_scan(mtd, 1)) {
- retval = -ENODEV;
+ retval = nand_scan(mtd, 1);
+ if (retval)
goto err_irq;
- }
+
/* Register the partitions */
retval = mtd_device_parse_register(mtd, NULL, NULL,
data ? data->partition : NULL,
--
1.9.1

2016-11-04 10:42:08

by Masahiro Yamada

[permalink] [raw]
Subject: [PATCH 09/22] mtd: nand: plat_nand: return error code of nand_scan() on error

The nand_scan() returns an appropriate error value when it fails.
Use it instead of the fixed error code -ENXIO.

Signed-off-by: Masahiro Yamada <[email protected]>
---

drivers/mtd/nand/plat_nand.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/nand/plat_nand.c b/drivers/mtd/nand/plat_nand.c
index 415a53a..791de3e 100644
--- a/drivers/mtd/nand/plat_nand.c
+++ b/drivers/mtd/nand/plat_nand.c
@@ -86,10 +86,9 @@ static int plat_nand_probe(struct platform_device *pdev)
}

/* Scan to find existence of the device */
- if (nand_scan(mtd, pdata->chip.nr_chips)) {
- err = -ENXIO;
+ err = nand_scan(mtd, pdata->chip.nr_chips);
+ if (err)
goto out;
- }

part_types = pdata->chip.part_probe_types;

--
1.9.1

2016-11-04 10:45:42

by Masahiro Yamada

[permalink] [raw]
Subject: [PATCH 15/22] mtd: nand: mxc: return error code of nand_scan_ident/tail() on error

The nand_scan_ident/tail() returns an appropriate error value when
it fails. Use it instead of the fixed error code -ENXIO.

Signed-off-by: Masahiro Yamada <[email protected]>
---

drivers/mtd/nand/mxc_nand.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/mtd/nand/mxc_nand.c b/drivers/mtd/nand/mxc_nand.c
index d7f724b..61ca020 100644
--- a/drivers/mtd/nand/mxc_nand.c
+++ b/drivers/mtd/nand/mxc_nand.c
@@ -1747,10 +1747,9 @@ static int mxcnd_probe(struct platform_device *pdev)
}

/* first scan to find the device and get the page size */
- if (nand_scan_ident(mtd, is_imx25_nfc(host) ? 4 : 1, NULL)) {
- err = -ENXIO;
+ err = nand_scan_ident(mtd, is_imx25_nfc(host) ? 4 : 1, NULL);
+ if (err)
goto escan;
- }

switch (this->ecc.mode) {
case NAND_ECC_HW:
@@ -1808,10 +1807,9 @@ static int mxcnd_probe(struct platform_device *pdev)
}

/* second phase scan */
- if (nand_scan_tail(mtd)) {
- err = -ENXIO;
+ err = nand_scan_tail(mtd);
+ if (err)
goto escan;
- }

/* Register the partitions */
mtd_device_parse_register(mtd, part_probes,
--
1.9.1

2016-11-04 10:45:57

by Masahiro Yamada

[permalink] [raw]
Subject: [PATCH 12/22] mtd: nand: fsmc: return error code of nand_scan_ident/tail() on error

The nand_scan_ident/tail() returns an appropriate error value when
it fails. Use it instead of the fixed error code -ENXIO.

Signed-off-by: Masahiro Yamada <[email protected]>
---

drivers/mtd/nand/fsmc_nand.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/mtd/nand/fsmc_nand.c b/drivers/mtd/nand/fsmc_nand.c
index d4f454a..4924b43 100644
--- a/drivers/mtd/nand/fsmc_nand.c
+++ b/drivers/mtd/nand/fsmc_nand.c
@@ -926,8 +926,8 @@ static int __init fsmc_nand_probe(struct platform_device *pdev)
/*
* Scan to find existence of the device
*/
- if (nand_scan_ident(mtd, 1, NULL)) {
- ret = -ENXIO;
+ ret = nand_scan_ident(mtd, 1, NULL);
+ if (ret) {
dev_err(&pdev->dev, "No NAND Device found!\n");
goto err_scan_ident;
}
@@ -992,10 +992,9 @@ static int __init fsmc_nand_probe(struct platform_device *pdev)
}

/* Second stage of scan to fill MTD data-structures */
- if (nand_scan_tail(mtd)) {
- ret = -ENXIO;
+ ret = nand_scan_tail(mtd);
+ if (ret)
goto err_probe;
- }

/*
* The partition information can is accessed by (in the same precedence)
--
1.9.1

2016-11-04 10:42:02

by Masahiro Yamada

[permalink] [raw]
Subject: [PATCH 07/22] mtd: nand: orion: return error code of nand_scan() on error

The nand_scan() returns an appropriate error value when it fails.
Use it instead of the fixed error code -ENXIO.

Signed-off-by: Masahiro Yamada <[email protected]>
---

drivers/mtd/nand/orion_nand.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/nand/orion_nand.c b/drivers/mtd/nand/orion_nand.c
index 40a7c4a..4a91c5d 100644
--- a/drivers/mtd/nand/orion_nand.c
+++ b/drivers/mtd/nand/orion_nand.c
@@ -155,10 +155,9 @@ static int __init orion_nand_probe(struct platform_device *pdev)
clk_put(clk);
}

- if (nand_scan(mtd, 1)) {
- ret = -ENXIO;
+ ret = nand_scan(mtd, 1);
+ if (ret)
goto no_dev;
- }

mtd->name = "orion_nand";
ret = mtd_device_register(mtd, board->parts, board->nr_parts);
--
1.9.1

2016-11-04 10:46:28

by Masahiro Yamada

[permalink] [raw]
Subject: [PATCH 16/22] mtd: nand: omap2: return error code of nand_scan_ident/tail() on error

The nand_scan_ident/tail() returns an appropriate error value when
it fails. Use it instead of the fixed error code -ENXIO.

Signed-off-by: Masahiro Yamada <[email protected]>
---

drivers/mtd/nand/omap2.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/mtd/nand/omap2.c b/drivers/mtd/nand/omap2.c
index 5513bfd9..6c985d3 100644
--- a/drivers/mtd/nand/omap2.c
+++ b/drivers/mtd/nand/omap2.c
@@ -1895,10 +1895,10 @@ static int omap_nand_probe(struct platform_device *pdev)

/* scan NAND device connected to chip controller */
nand_chip->options |= info->devsize & NAND_BUSWIDTH_16;
- if (nand_scan_ident(mtd, 1, NULL)) {
+ err = nand_scan_ident(mtd, 1, NULL);
+ if (err) {
dev_err(&info->pdev->dev,
"scan failed, may be bus-width mismatch\n");
- err = -ENXIO;
goto return_error;
}

@@ -2154,10 +2154,9 @@ static int omap_nand_probe(struct platform_device *pdev)

scan_tail:
/* second phase scan */
- if (nand_scan_tail(mtd)) {
- err = -ENXIO;
+ err = nand_scan_tail(mtd);
+ if (err)
goto return_error;
- }

if (dev->of_node)
mtd_device_register(mtd, NULL, 0);
--
1.9.1

2016-11-04 10:46:26

by Masahiro Yamada

[permalink] [raw]
Subject: [PATCH 01/22] mtd: nand: ams-delta: return error code of nand_scan() on error

The nand_scan() returns an appropriate error value when it fails.
Use it instead of the fixed error code -ENXIO.

Signed-off-by: Masahiro Yamada <[email protected]>
---

drivers/mtd/nand/ams-delta.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/nand/ams-delta.c b/drivers/mtd/nand/ams-delta.c
index 78e12cc..5d6c26f 100644
--- a/drivers/mtd/nand/ams-delta.c
+++ b/drivers/mtd/nand/ams-delta.c
@@ -234,10 +234,9 @@ static int ams_delta_init(struct platform_device *pdev)
goto out_gpio;

/* Scan to find existence of the device */
- if (nand_scan(ams_delta_mtd, 1)) {
- err = -ENXIO;
+ err = nand_scan(ams_delta_mtd, 1);
+ if (err)
goto out_mtd;
- }

/* Register the partitions */
mtd_device_register(ams_delta_mtd, partition_info,
--
1.9.1

2016-11-05 07:36:09

by Marek Vasut

[permalink] [raw]
Subject: Re: [PATCH 00/22] mtd: nand: return error code of nand_scan(_ident, _tail) on error

On 11/04/2016 11:42 AM, Masahiro Yamada wrote:
>
> nand_scan(), nand_scan_ident(), nand_scan_tail() return
> an appropriate negative value on error.
>
> Most of drivers return the value from them on error,
> but some of them return the fixed error code -ENXIO
> (and a few return -ENODEV).
>
> This series make those drivers return more precise error code.
>

Reviewed-by: Marek Vasut <[email protected]>

Nice cleanup, thanks!

--
Best regards,
Marek Vasut

2016-11-06 01:37:20

by Vladimir Zapolskiy

[permalink] [raw]
Subject: Re: [PATCH 13/22] mtd: nand: lpc32xx: return error code of nand_scan_ident/tail() on error

On 11/04/2016 12:43 PM, Masahiro Yamada wrote:
> The nand_scan_ident/tail() returns an appropriate error value when
> it fails. Use it instead of the fixed error code -ENXIO.
>
> Signed-off-by: Masahiro Yamada <[email protected]>
> ---

Acked-by: Vladimir Zapolskiy <[email protected]>

Thank you for the change.

--
With best wishes,
Vladimir

2016-11-06 18:37:41

by Boris Brezillon

[permalink] [raw]
Subject: Re: [PATCH 13/22] mtd: nand: lpc32xx: return error code of nand_scan_ident/tail() on error

On Fri, 4 Nov 2016 19:43:01 +0900
Masahiro Yamada <[email protected]> wrote:

> The nand_scan_ident/tail() returns an appropriate error value when
> it fails. Use it instead of the fixed error code -ENXIO.
>
> Signed-off-by: Masahiro Yamada <[email protected]>
> ---
>
> drivers/mtd/nand/lpc32xx_mlc.c | 10 ++++------
> drivers/mtd/nand/lpc32xx_slc.c | 9 +++------
> 2 files changed, 7 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/mtd/nand/lpc32xx_mlc.c b/drivers/mtd/nand/lpc32xx_mlc.c
> index 8523881..5553a5d 100644
> --- a/drivers/mtd/nand/lpc32xx_mlc.c
> +++ b/drivers/mtd/nand/lpc32xx_mlc.c
> @@ -747,10 +747,9 @@ static int lpc32xx_nand_probe(struct platform_device *pdev)
> * Scan to find existance of the device and
> * Get the type of NAND device SMALL block or LARGE block
> */
> - if (nand_scan_ident(mtd, 1, NULL)) {
> - res = -ENXIO;
> + res = nand_scan_ident(mtd, 1, NULL);
> + if (res)
> goto err_exit3;
> - }
>
> host->dma_buf = devm_kzalloc(&pdev->dev, mtd->writesize, GFP_KERNEL);
> if (!host->dma_buf) {
> @@ -793,10 +792,9 @@ static int lpc32xx_nand_probe(struct platform_device *pdev)
> * Fills out all the uninitialized function pointers with the defaults
> * And scans for a bad block table if appropriate.
> */
> - if (nand_scan_tail(mtd)) {
> - res = -ENXIO;
> + res = nand_scan_tail(mtd);
> + if (res)
> goto err_exit4;
> - }
>
> mtd->name = DRV_NAME;
>
> diff --git a/drivers/mtd/nand/lpc32xx_slc.c b/drivers/mtd/nand/lpc32xx_slc.c
> index 8d3edc3..f1094e5 100644
> --- a/drivers/mtd/nand/lpc32xx_slc.c
> +++ b/drivers/mtd/nand/lpc32xx_slc.c
> @@ -894,10 +894,9 @@ static int lpc32xx_nand_probe(struct platform_device *pdev)
> }
>
> /* Find NAND device */
> - if (nand_scan_ident(mtd, 1, NULL)) {
> - res = -ENXIO;
> + res = nand_scan_ident(mtd, 1, NULL);
> + if (res)
> goto err_exit3;
> - }
>
> /* OOB and ECC CPU and DMA work areas */
> host->ecc_buf = (uint32_t *)(host->data_buf + LPC32XX_DMA_DATA_SIZE);
> @@ -929,10 +928,8 @@ static int lpc32xx_nand_probe(struct platform_device *pdev)
> /*
> * Fills out all the uninitialized function pointers with the defaults
> */
> - if (nand_scan_tail(mtd)) {
> - res = -ENXIO;
> + res = nand_scan_tail(mtd);

You miss

if (res)

here.

No need to resend, I'll fix it when applying the patches.

> goto err_exit3;
> - }
>
> mtd->name = "nxp_lpc3220_slc";
> res = mtd_device_register(mtd, host->ncfg->parts,

2016-11-06 22:55:57

by Boris Brezillon

[permalink] [raw]
Subject: Re: [PATCH 00/22] mtd: nand: return error code of nand_scan(_ident,_tail) on error

On Fri, 4 Nov 2016 19:42:48 +0900
Masahiro Yamada <[email protected]> wrote:

> nand_scan(), nand_scan_ident(), nand_scan_tail() return
> an appropriate negative value on error.
>
> Most of drivers return the value from them on error,
> but some of them return the fixed error code -ENXIO
> (and a few return -ENODEV).
>
> This series make those drivers return more precise error code.

Applied and fixed the bug I found in patch 13.

Thanks,

Boris

>
>
> Masahiro Yamada (22):
> mtd: nand: ams-delta: return error code of nand_scan() on error
> mtd: nand: cmx270: return error code of nand_scan() on error
> mtd: nand: cs553x: return error code of nand_scan() on error
> mtd: nand: gpio: return error code of nand_scan() on error
> mtd: nand: mpc5121: return error code of nand_scan() on error
> mtd: nand: tmio: return error code of nand_scan() on error
> mtd: nand: orion: return error code of nand_scan() on error
> mtd: nand: pasemi: return error code of nand_scan() on error
> mtd: nand: plat_nand: return error code of nand_scan() on error
> mtd: nand: atmel: return error code of nand_scan_ident/tail() on error
> mtd: nand: brcmnand: return error code of nand_scan_ident/tail() on
> error
> mtd: nand: fsmc: return error code of nand_scan_ident/tail() on error
> mtd: nand: lpc32xx: return error code of nand_scan_ident/tail() on
> error
> mtd: nand: mediatek: return error code of nand_scan_ident/tail() on
> error
> mtd: nand: mxc: return error code of nand_scan_ident/tail() on error
> mtd: nand: omap2: return error code of nand_scan_ident/tail() on error
> mtd: nand: vf610: return error code of nand_scan_ident/tail() on error
> mtd: nand: cafe: return error code of nand_scan_ident() on error
> mtd: nand: hisi504: return error code of nand_scan_ident() on error
> mtd: nand: pxa3xx: return error code of nand_scan_ident() on error
> mtd: nand: nandsim: remove unneeded checks for nand_scan_ident/tail()
> mtd: nand: socrates: use nand_scan() for nand_scan_ident/tail() combo
>
> drivers/mtd/nand/ams-delta.c | 5 ++---
> drivers/mtd/nand/atmel_nand.c | 10 ++++------
> drivers/mtd/nand/brcmnand/brcmnand.c | 10 ++++++----
> drivers/mtd/nand/cafe_nand.c | 5 ++---
> drivers/mtd/nand/cmx270_nand.c | 4 ++--
> drivers/mtd/nand/cs553x_nand.c | 5 ++---
> drivers/mtd/nand/fsmc_nand.c | 9 ++++-----
> drivers/mtd/nand/gpio.c | 5 ++---
> drivers/mtd/nand/hisi504_nand.c | 4 +---
> drivers/mtd/nand/lpc32xx_mlc.c | 10 ++++------
> drivers/mtd/nand/lpc32xx_slc.c | 9 +++------
> drivers/mtd/nand/mpc5121_nfc.c | 4 ++--
> drivers/mtd/nand/mtk_nand.c | 4 ++--
> drivers/mtd/nand/mxc_nand.c | 10 ++++------
> drivers/mtd/nand/nandsim.c | 4 ----
> drivers/mtd/nand/omap2.c | 9 ++++-----
> drivers/mtd/nand/orion_nand.c | 5 ++---
> drivers/mtd/nand/pasemi_nand.c | 5 ++---
> drivers/mtd/nand/plat_nand.c | 5 ++---
> drivers/mtd/nand/pxa3xx_nand.c | 5 +++--
> drivers/mtd/nand/socrates_nand.c | 12 ++----------
> drivers/mtd/nand/tmio_nand.c | 6 +++---
> drivers/mtd/nand/vf610_nfc.c | 10 ++++------
> 23 files changed, 62 insertions(+), 93 deletions(-)
>

2016-11-07 00:30:20

by Vladimir Zapolskiy

[permalink] [raw]
Subject: Re: [PATCH 13/22] mtd: nand: lpc32xx: return error code of nand_scan_ident/tail() on error

Hi Boris,

On 11/06/2016 08:27 PM, Boris Brezillon wrote:
> On Fri, 4 Nov 2016 19:43:01 +0900
> Masahiro Yamada <[email protected]> wrote:
>
>> The nand_scan_ident/tail() returns an appropriate error value when
>> it fails. Use it instead of the fixed error code -ENXIO.
>>
>> Signed-off-by: Masahiro Yamada <[email protected]>
>> ---

[snip]

>> - if (nand_scan_tail(mtd)) {
>> - res = -ENXIO;
>> + res = nand_scan_tail(mtd);
>
> You miss
>
> if (res)
>
> here.
>
> No need to resend, I'll fix it when applying the patches.
>
>> goto err_exit3;
>> - }
>>

nice catch, thank you for noticing and fixing the overlooked bug!

--
With best wishes,
Vladimir