vf610_nfc_probe() misses error handling of mtd_device_register().
Found by Linux Driver Verification project (linuxtesting.org).
Signed-off-by: Alexey Khoroshilov <[email protected]>
---
drivers/mtd/nand/vf610_nfc.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/mtd/nand/vf610_nfc.c b/drivers/mtd/nand/vf610_nfc.c
index 8037d4b48a05..a4c181af74b3 100644
--- a/drivers/mtd/nand/vf610_nfc.c
+++ b/drivers/mtd/nand/vf610_nfc.c
@@ -782,7 +782,10 @@ static int vf610_nfc_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, mtd);
/* Register device in MTD */
- return mtd_device_register(mtd, NULL, 0);
+ err = mtd_device_register(mtd, NULL, 0);
+ if (err)
+ goto error;
+ return 0;
error:
of_node_put(nand_get_flash_node(chip));
--
2.7.4
On Sat, 23 Dec 2017 00:43:14 +0300
Alexey Khoroshilov <[email protected]> wrote:
> vf610_nfc_probe() misses error handling of mtd_device_register().
>
> Found by Linux Driver Verification project (linuxtesting.org).
>
> Signed-off-by: Alexey Khoroshilov <[email protected]>
> ---
> drivers/mtd/nand/vf610_nfc.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/mtd/nand/vf610_nfc.c b/drivers/mtd/nand/vf610_nfc.c
> index 8037d4b48a05..a4c181af74b3 100644
> --- a/drivers/mtd/nand/vf610_nfc.c
> +++ b/drivers/mtd/nand/vf610_nfc.c
> @@ -782,7 +782,10 @@ static int vf610_nfc_probe(struct platform_device *pdev)
> platform_set_drvdata(pdev, mtd);
>
> /* Register device in MTD */
> - return mtd_device_register(mtd, NULL, 0);
> + err = mtd_device_register(mtd, NULL, 0);
> + if (err)
> + goto error;
Nope, you're not entirely fixing the leak: nand_scan_tail() has to be
undone with nand_cleanup().
> + return 0;
>
> error:
> of_node_put(nand_get_flash_node(chip));
vf610_nfc_probe() misses error handling of mtd_device_register().
Found by Linux Driver Verification project (linuxtesting.org).
Signed-off-by: Alexey Khoroshilov <[email protected]>
---
v2: Add nand_cleanup() to undone nand_scan_tail() as Boris Brezillon noted.
drivers/mtd/nand/vf610_nfc.c | 25 +++++++++++++++----------
1 file changed, 15 insertions(+), 10 deletions(-)
diff --git a/drivers/mtd/nand/vf610_nfc.c b/drivers/mtd/nand/vf610_nfc.c
index 8037d4b48a05..2dac25a8ccbf 100644
--- a/drivers/mtd/nand/vf610_nfc.c
+++ b/drivers/mtd/nand/vf610_nfc.c
@@ -682,7 +682,7 @@ static int vf610_nfc_probe(struct platform_device *pdev)
dev_err(nfc->dev,
"Only one NAND chip supported!\n");
err = -EINVAL;
- goto error;
+ goto err_node;
}
nand_set_flash_node(chip, child);
@@ -712,7 +712,7 @@ static int vf610_nfc_probe(struct platform_device *pdev)
err = devm_request_irq(nfc->dev, irq, vf610_nfc_irq, 0, DRV_NAME, mtd);
if (err) {
dev_err(nfc->dev, "Error requesting IRQ!\n");
- goto error;
+ goto err_node;
}
vf610_nfc_preinit_controller(nfc);
@@ -720,7 +720,7 @@ static int vf610_nfc_probe(struct platform_device *pdev)
/* first scan to find the device and get the page size */
err = nand_scan_ident(mtd, 1, NULL);
if (err)
- goto error;
+ goto err_node;
vf610_nfc_init_controller(nfc);
@@ -732,20 +732,20 @@ static int vf610_nfc_probe(struct platform_device *pdev)
if (mtd->writesize + mtd->oobsize > PAGE_2K + OOB_MAX - 8) {
dev_err(nfc->dev, "Unsupported flash page size\n");
err = -ENXIO;
- goto error;
+ goto err_node;
}
if (chip->ecc.mode == NAND_ECC_HW) {
if (mtd->writesize != PAGE_2K && mtd->oobsize < 64) {
dev_err(nfc->dev, "Unsupported flash with hwecc\n");
err = -ENXIO;
- goto error;
+ goto err_node;
}
if (chip->ecc.size != mtd->writesize) {
dev_err(nfc->dev, "Step size needs to be page size\n");
err = -ENXIO;
- goto error;
+ goto err_node;
}
/* Only 64 byte ECC layouts known */
@@ -765,7 +765,7 @@ static int vf610_nfc_probe(struct platform_device *pdev)
} else {
dev_err(nfc->dev, "Unsupported ECC strength\n");
err = -ENXIO;
- goto error;
+ goto err_node;
}
chip->ecc.read_page = vf610_nfc_read_page;
@@ -777,14 +777,19 @@ static int vf610_nfc_probe(struct platform_device *pdev)
/* second phase scan */
err = nand_scan_tail(mtd);
if (err)
- goto error;
+ goto err_node;
platform_set_drvdata(pdev, mtd);
/* Register device in MTD */
- return mtd_device_register(mtd, NULL, 0);
+ err = mtd_device_register(mtd, NULL, 0);
+ if (err)
+ goto err_nand;
+ return 0;
-error:
+err_nand:
+ nand_cleanup(chip);
+err_node:
of_node_put(nand_get_flash_node(chip));
err_clk:
clk_disable_unprepare(nfc->clk);
--
2.7.4
On Sat, 23 Dec 2017 22:18:26 +0300
Alexey Khoroshilov <[email protected]> wrote:
> vf610_nfc_probe() misses error handling of mtd_device_register().
>
> Found by Linux Driver Verification project (linuxtesting.org).
>
> Signed-off-by: Alexey Khoroshilov <[email protected]>
> ---
> v2: Add nand_cleanup() to undone nand_scan_tail() as Boris Brezillon noted.
>
> drivers/mtd/nand/vf610_nfc.c | 25 +++++++++++++++----------
> 1 file changed, 15 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/mtd/nand/vf610_nfc.c b/drivers/mtd/nand/vf610_nfc.c
> index 8037d4b48a05..2dac25a8ccbf 100644
> --- a/drivers/mtd/nand/vf610_nfc.c
> +++ b/drivers/mtd/nand/vf610_nfc.c
> @@ -682,7 +682,7 @@ static int vf610_nfc_probe(struct platform_device *pdev)
> dev_err(nfc->dev,
> "Only one NAND chip supported!\n");
> err = -EINVAL;
> - goto error;
> + goto err_node;
> }
>
> nand_set_flash_node(chip, child);
> @@ -712,7 +712,7 @@ static int vf610_nfc_probe(struct platform_device *pdev)
> err = devm_request_irq(nfc->dev, irq, vf610_nfc_irq, 0, DRV_NAME, mtd);
> if (err) {
> dev_err(nfc->dev, "Error requesting IRQ!\n");
> - goto error;
> + goto err_node;
> }
>
> vf610_nfc_preinit_controller(nfc);
> @@ -720,7 +720,7 @@ static int vf610_nfc_probe(struct platform_device *pdev)
> /* first scan to find the device and get the page size */
> err = nand_scan_ident(mtd, 1, NULL);
> if (err)
> - goto error;
> + goto err_node;
>
> vf610_nfc_init_controller(nfc);
>
> @@ -732,20 +732,20 @@ static int vf610_nfc_probe(struct platform_device *pdev)
> if (mtd->writesize + mtd->oobsize > PAGE_2K + OOB_MAX - 8) {
> dev_err(nfc->dev, "Unsupported flash page size\n");
> err = -ENXIO;
> - goto error;
> + goto err_node;
> }
>
> if (chip->ecc.mode == NAND_ECC_HW) {
> if (mtd->writesize != PAGE_2K && mtd->oobsize < 64) {
> dev_err(nfc->dev, "Unsupported flash with hwecc\n");
> err = -ENXIO;
> - goto error;
> + goto err_node;
> }
>
> if (chip->ecc.size != mtd->writesize) {
> dev_err(nfc->dev, "Step size needs to be page size\n");
> err = -ENXIO;
> - goto error;
> + goto err_node;
> }
>
> /* Only 64 byte ECC layouts known */
> @@ -765,7 +765,7 @@ static int vf610_nfc_probe(struct platform_device *pdev)
> } else {
> dev_err(nfc->dev, "Unsupported ECC strength\n");
> err = -ENXIO;
> - goto error;
> + goto err_node;
> }
>
> chip->ecc.read_page = vf610_nfc_read_page;
> @@ -777,14 +777,19 @@ static int vf610_nfc_probe(struct platform_device *pdev)
> /* second phase scan */
> err = nand_scan_tail(mtd);
> if (err)
> - goto error;
> + goto err_node;
>
> platform_set_drvdata(pdev, mtd);
>
> /* Register device in MTD */
> - return mtd_device_register(mtd, NULL, 0);
> + err = mtd_device_register(mtd, NULL, 0);
> + if (err)
> + goto err_nand;
> + return 0;
>
> -error:
> +err_nand:
> + nand_cleanup(chip);
> +err_node:
> of_node_put(nand_get_flash_node(chip));
Can you use clearer err labels, like err_put_node and err_cleanup_nand?
> err_clk:
> clk_disable_unprepare(nfc->clk);
On Sat, 23 Dec 2017 22:18:26 +0300
Alexey Khoroshilov <[email protected]> wrote:
> vf610_nfc_probe() misses error handling of mtd_device_register().
>
> Found by Linux Driver Verification project (linuxtesting.org).
>
> Signed-off-by: Alexey Khoroshilov <[email protected]>
> ---
> v2: Add nand_cleanup() to undone nand_scan_tail() as Boris Brezillon noted.
>
> drivers/mtd/nand/vf610_nfc.c | 25 +++++++++++++++----------
> 1 file changed, 15 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/mtd/nand/vf610_nfc.c b/drivers/mtd/nand/vf610_nfc.c
> index 8037d4b48a05..2dac25a8ccbf 100644
> --- a/drivers/mtd/nand/vf610_nfc.c
> +++ b/drivers/mtd/nand/vf610_nfc.c
> @@ -682,7 +682,7 @@ static int vf610_nfc_probe(struct platform_device *pdev)
> dev_err(nfc->dev,
> "Only one NAND chip supported!\n");
> err = -EINVAL;
> - goto error;
> + goto err_node;
> }
>
> nand_set_flash_node(chip, child);
> @@ -712,7 +712,7 @@ static int vf610_nfc_probe(struct platform_device *pdev)
> err = devm_request_irq(nfc->dev, irq, vf610_nfc_irq, 0, DRV_NAME, mtd);
> if (err) {
> dev_err(nfc->dev, "Error requesting IRQ!\n");
> - goto error;
> + goto err_node;
> }
>
> vf610_nfc_preinit_controller(nfc);
> @@ -720,7 +720,7 @@ static int vf610_nfc_probe(struct platform_device *pdev)
> /* first scan to find the device and get the page size */
> err = nand_scan_ident(mtd, 1, NULL);
> if (err)
> - goto error;
> + goto err_node;
>
> vf610_nfc_init_controller(nfc);
>
> @@ -732,20 +732,20 @@ static int vf610_nfc_probe(struct platform_device *pdev)
> if (mtd->writesize + mtd->oobsize > PAGE_2K + OOB_MAX - 8) {
> dev_err(nfc->dev, "Unsupported flash page size\n");
> err = -ENXIO;
> - goto error;
> + goto err_node;
> }
>
> if (chip->ecc.mode == NAND_ECC_HW) {
> if (mtd->writesize != PAGE_2K && mtd->oobsize < 64) {
> dev_err(nfc->dev, "Unsupported flash with hwecc\n");
> err = -ENXIO;
> - goto error;
> + goto err_node;
> }
>
> if (chip->ecc.size != mtd->writesize) {
> dev_err(nfc->dev, "Step size needs to be page size\n");
> err = -ENXIO;
> - goto error;
> + goto err_node;
> }
>
> /* Only 64 byte ECC layouts known */
> @@ -765,7 +765,7 @@ static int vf610_nfc_probe(struct platform_device *pdev)
> } else {
> dev_err(nfc->dev, "Unsupported ECC strength\n");
> err = -ENXIO;
> - goto error;
> + goto err_node;
> }
>
> chip->ecc.read_page = vf610_nfc_read_page;
> @@ -777,14 +777,19 @@ static int vf610_nfc_probe(struct platform_device *pdev)
> /* second phase scan */
> err = nand_scan_tail(mtd);
> if (err)
> - goto error;
> + goto err_node;
>
> platform_set_drvdata(pdev, mtd);
>
> /* Register device in MTD */
> - return mtd_device_register(mtd, NULL, 0);
> + err = mtd_device_register(mtd, NULL, 0);
> + if (err)
> + goto err_nand;
> + return 0;
>
> -error:
> +err_nand:
> + nand_cleanup(chip);
> +err_node:
> of_node_put(nand_get_flash_node(chip));
I also realize calling of_node_put() here is wrong because nothing in
this code retains a reference to the DT node.
> err_clk:
> clk_disable_unprepare(nfc->clk);
vf610_nfc_probe() misses error handling of mtd_device_register()
and contains unneeded of_node_put() on error path.
Found by Linux Driver Verification project (linuxtesting.org).
Signed-off-by: Alexey Khoroshilov <[email protected]>
---
v2: Add nand_cleanup() to undone nand_scan_tail() as Boris Brezillon noted.
v3: Rename error labels, remove of_node_put() per Boris Brezillon request.
drivers/mtd/nand/vf610_nfc.c | 29 ++++++++++++++++-------------
1 file changed, 16 insertions(+), 13 deletions(-)
diff --git a/drivers/mtd/nand/vf610_nfc.c b/drivers/mtd/nand/vf610_nfc.c
index 8037d4b48a05..7cdc6eed305d 100644
--- a/drivers/mtd/nand/vf610_nfc.c
+++ b/drivers/mtd/nand/vf610_nfc.c
@@ -682,7 +682,7 @@ static int vf610_nfc_probe(struct platform_device *pdev)
dev_err(nfc->dev,
"Only one NAND chip supported!\n");
err = -EINVAL;
- goto error;
+ goto err_disable_clk;
}
nand_set_flash_node(chip, child);
@@ -692,7 +692,7 @@ static int vf610_nfc_probe(struct platform_device *pdev)
if (!nand_get_flash_node(chip)) {
dev_err(nfc->dev, "NAND chip sub-node missing!\n");
err = -ENODEV;
- goto err_clk;
+ goto err_disable_clk;
}
chip->dev_ready = vf610_nfc_dev_ready;
@@ -712,7 +712,7 @@ static int vf610_nfc_probe(struct platform_device *pdev)
err = devm_request_irq(nfc->dev, irq, vf610_nfc_irq, 0, DRV_NAME, mtd);
if (err) {
dev_err(nfc->dev, "Error requesting IRQ!\n");
- goto error;
+ goto err_disable_clk;
}
vf610_nfc_preinit_controller(nfc);
@@ -720,7 +720,7 @@ static int vf610_nfc_probe(struct platform_device *pdev)
/* first scan to find the device and get the page size */
err = nand_scan_ident(mtd, 1, NULL);
if (err)
- goto error;
+ goto err_disable_clk;
vf610_nfc_init_controller(nfc);
@@ -732,20 +732,20 @@ static int vf610_nfc_probe(struct platform_device *pdev)
if (mtd->writesize + mtd->oobsize > PAGE_2K + OOB_MAX - 8) {
dev_err(nfc->dev, "Unsupported flash page size\n");
err = -ENXIO;
- goto error;
+ goto err_disable_clk;
}
if (chip->ecc.mode == NAND_ECC_HW) {
if (mtd->writesize != PAGE_2K && mtd->oobsize < 64) {
dev_err(nfc->dev, "Unsupported flash with hwecc\n");
err = -ENXIO;
- goto error;
+ goto err_disable_clk;
}
if (chip->ecc.size != mtd->writesize) {
dev_err(nfc->dev, "Step size needs to be page size\n");
err = -ENXIO;
- goto error;
+ goto err_disable_clk;
}
/* Only 64 byte ECC layouts known */
@@ -765,7 +765,7 @@ static int vf610_nfc_probe(struct platform_device *pdev)
} else {
dev_err(nfc->dev, "Unsupported ECC strength\n");
err = -ENXIO;
- goto error;
+ goto err_disable_clk;
}
chip->ecc.read_page = vf610_nfc_read_page;
@@ -777,16 +777,19 @@ static int vf610_nfc_probe(struct platform_device *pdev)
/* second phase scan */
err = nand_scan_tail(mtd);
if (err)
- goto error;
+ goto err_disable_clk;
platform_set_drvdata(pdev, mtd);
/* Register device in MTD */
- return mtd_device_register(mtd, NULL, 0);
+ err = mtd_device_register(mtd, NULL, 0);
+ if (err)
+ goto err_cleanup_nand;
+ return 0;
-error:
- of_node_put(nand_get_flash_node(chip));
-err_clk:
+err_cleanup_nand:
+ nand_cleanup(chip);
+err_disable_clk:
clk_disable_unprepare(nfc->clk);
return err;
}
--
2.7.4
On Sat, 27 Jan 2018 01:32:41 +0300
Alexey Khoroshilov <[email protected]> wrote:
> vf610_nfc_probe() misses error handling of mtd_device_register()
> and contains unneeded of_node_put() on error path.
>
> Found by Linux Driver Verification project (linuxtesting.org).
>
> Signed-off-by: Alexey Khoroshilov <[email protected]>
> ---
> v2: Add nand_cleanup() to undone nand_scan_tail() as Boris Brezillon noted.
> v3: Rename error labels, remove of_node_put() per Boris Brezillon request.
Should be separated in 3 patches IMO:
1/ remove the unnecessary of_node_put()
2/ rename error label into err_disable_clk
3/ check mtd_device_register() return code
>
> drivers/mtd/nand/vf610_nfc.c | 29 ++++++++++++++++-------------
> 1 file changed, 16 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/mtd/nand/vf610_nfc.c b/drivers/mtd/nand/vf610_nfc.c
> index 8037d4b48a05..7cdc6eed305d 100644
> --- a/drivers/mtd/nand/vf610_nfc.c
> +++ b/drivers/mtd/nand/vf610_nfc.c
> @@ -682,7 +682,7 @@ static int vf610_nfc_probe(struct platform_device *pdev)
> dev_err(nfc->dev,
> "Only one NAND chip supported!\n");
> err = -EINVAL;
> - goto error;
> + goto err_disable_clk;
> }
>
> nand_set_flash_node(chip, child);
> @@ -692,7 +692,7 @@ static int vf610_nfc_probe(struct platform_device *pdev)
> if (!nand_get_flash_node(chip)) {
> dev_err(nfc->dev, "NAND chip sub-node missing!\n");
> err = -ENODEV;
> - goto err_clk;
> + goto err_disable_clk;
> }
>
> chip->dev_ready = vf610_nfc_dev_ready;
> @@ -712,7 +712,7 @@ static int vf610_nfc_probe(struct platform_device *pdev)
> err = devm_request_irq(nfc->dev, irq, vf610_nfc_irq, 0, DRV_NAME, mtd);
> if (err) {
> dev_err(nfc->dev, "Error requesting IRQ!\n");
> - goto error;
> + goto err_disable_clk;
> }
>
> vf610_nfc_preinit_controller(nfc);
> @@ -720,7 +720,7 @@ static int vf610_nfc_probe(struct platform_device *pdev)
> /* first scan to find the device and get the page size */
> err = nand_scan_ident(mtd, 1, NULL);
> if (err)
> - goto error;
> + goto err_disable_clk;
>
> vf610_nfc_init_controller(nfc);
>
> @@ -732,20 +732,20 @@ static int vf610_nfc_probe(struct platform_device *pdev)
> if (mtd->writesize + mtd->oobsize > PAGE_2K + OOB_MAX - 8) {
> dev_err(nfc->dev, "Unsupported flash page size\n");
> err = -ENXIO;
> - goto error;
> + goto err_disable_clk;
> }
>
> if (chip->ecc.mode == NAND_ECC_HW) {
> if (mtd->writesize != PAGE_2K && mtd->oobsize < 64) {
> dev_err(nfc->dev, "Unsupported flash with hwecc\n");
> err = -ENXIO;
> - goto error;
> + goto err_disable_clk;
> }
>
> if (chip->ecc.size != mtd->writesize) {
> dev_err(nfc->dev, "Step size needs to be page size\n");
> err = -ENXIO;
> - goto error;
> + goto err_disable_clk;
> }
>
> /* Only 64 byte ECC layouts known */
> @@ -765,7 +765,7 @@ static int vf610_nfc_probe(struct platform_device *pdev)
> } else {
> dev_err(nfc->dev, "Unsupported ECC strength\n");
> err = -ENXIO;
> - goto error;
> + goto err_disable_clk;
> }
>
> chip->ecc.read_page = vf610_nfc_read_page;
> @@ -777,16 +777,19 @@ static int vf610_nfc_probe(struct platform_device *pdev)
> /* second phase scan */
> err = nand_scan_tail(mtd);
> if (err)
> - goto error;
> + goto err_disable_clk;
>
> platform_set_drvdata(pdev, mtd);
>
> /* Register device in MTD */
> - return mtd_device_register(mtd, NULL, 0);
> + err = mtd_device_register(mtd, NULL, 0);
> + if (err)
> + goto err_cleanup_nand;
> + return 0;
>
> -error:
> - of_node_put(nand_get_flash_node(chip));
> -err_clk:
> +err_cleanup_nand:
> + nand_cleanup(chip);
> +err_disable_clk:
> clk_disable_unprepare(nfc->clk);
> return err;
> }
vf610_nfc_probe() misses error handling of mtd_device_register()
and contains unneeded of_node_put() on error path.
v2: Add nand_cleanup() to undone nand_scan_tail() as Boris Brezillon noted.
v3: Rename error labels, remove of_node_put() per Boris Brezillon request.
v4: Separate fix in to 3 patches.
Alexey Khoroshilov (3):
mtd: nand: vf610: remove the unnecessary of_node_put()
mtd: nand: vf610: improve readability of error label
mtd: nand: vf610: check mtd_device_register() return code
drivers/mtd/nand/vf610_nfc.c | 29 ++++++++++++++++-------------
1 file changed, 16 insertions(+), 13 deletions(-)
--
2.7.4
Calling of_node_put() in vf610_nfc_probe() is wrong because nothing in
this code retains a reference to the DT node.
Signed-off-by: Alexey Khoroshilov <[email protected]>
---
drivers/mtd/nand/vf610_nfc.c | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/drivers/mtd/nand/vf610_nfc.c b/drivers/mtd/nand/vf610_nfc.c
index 80d31a58e558..c4568372c3e3 100644
--- a/drivers/mtd/nand/vf610_nfc.c
+++ b/drivers/mtd/nand/vf610_nfc.c
@@ -682,7 +682,7 @@ static int vf610_nfc_probe(struct platform_device *pdev)
dev_err(nfc->dev,
"Only one NAND chip supported!\n");
err = -EINVAL;
- goto error;
+ goto err_clk;
}
nand_set_flash_node(chip, child);
@@ -712,7 +712,7 @@ static int vf610_nfc_probe(struct platform_device *pdev)
err = devm_request_irq(nfc->dev, irq, vf610_nfc_irq, 0, DRV_NAME, mtd);
if (err) {
dev_err(nfc->dev, "Error requesting IRQ!\n");
- goto error;
+ goto err_clk;
}
vf610_nfc_preinit_controller(nfc);
@@ -720,7 +720,7 @@ static int vf610_nfc_probe(struct platform_device *pdev)
/* first scan to find the device and get the page size */
err = nand_scan_ident(mtd, 1, NULL);
if (err)
- goto error;
+ goto err_clk;
vf610_nfc_init_controller(nfc);
@@ -732,20 +732,20 @@ static int vf610_nfc_probe(struct platform_device *pdev)
if (mtd->writesize + mtd->oobsize > PAGE_2K + OOB_MAX - 8) {
dev_err(nfc->dev, "Unsupported flash page size\n");
err = -ENXIO;
- goto error;
+ goto err_clk;
}
if (chip->ecc.mode == NAND_ECC_HW) {
if (mtd->writesize != PAGE_2K && mtd->oobsize < 64) {
dev_err(nfc->dev, "Unsupported flash with hwecc\n");
err = -ENXIO;
- goto error;
+ goto err_clk;
}
if (chip->ecc.size != mtd->writesize) {
dev_err(nfc->dev, "Step size needs to be page size\n");
err = -ENXIO;
- goto error;
+ goto err_clk;
}
/* Only 64 byte ECC layouts known */
@@ -765,7 +765,7 @@ static int vf610_nfc_probe(struct platform_device *pdev)
} else {
dev_err(nfc->dev, "Unsupported ECC strength\n");
err = -ENXIO;
- goto error;
+ goto err_clk;
}
chip->ecc.read_page = vf610_nfc_read_page;
@@ -777,15 +777,13 @@ static int vf610_nfc_probe(struct platform_device *pdev)
/* second phase scan */
err = nand_scan_tail(mtd);
if (err)
- goto error;
+ goto err_clk;
platform_set_drvdata(pdev, mtd);
/* Register device in MTD */
return mtd_device_register(mtd, NULL, 0);
-error:
- of_node_put(nand_get_flash_node(chip));
err_clk:
clk_disable_unprepare(nfc->clk);
return err;
--
2.7.4
Use clearer error labels as Boris Brezillon suggested.
Signed-off-by: Alexey Khoroshilov <[email protected]>
---
drivers/mtd/nand/vf610_nfc.c | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/drivers/mtd/nand/vf610_nfc.c b/drivers/mtd/nand/vf610_nfc.c
index c4568372c3e3..9cc5992e88c8 100644
--- a/drivers/mtd/nand/vf610_nfc.c
+++ b/drivers/mtd/nand/vf610_nfc.c
@@ -682,7 +682,7 @@ static int vf610_nfc_probe(struct platform_device *pdev)
dev_err(nfc->dev,
"Only one NAND chip supported!\n");
err = -EINVAL;
- goto err_clk;
+ goto err_disable_clk;
}
nand_set_flash_node(chip, child);
@@ -692,7 +692,7 @@ static int vf610_nfc_probe(struct platform_device *pdev)
if (!nand_get_flash_node(chip)) {
dev_err(nfc->dev, "NAND chip sub-node missing!\n");
err = -ENODEV;
- goto err_clk;
+ goto err_disable_clk;
}
chip->dev_ready = vf610_nfc_dev_ready;
@@ -712,7 +712,7 @@ static int vf610_nfc_probe(struct platform_device *pdev)
err = devm_request_irq(nfc->dev, irq, vf610_nfc_irq, 0, DRV_NAME, mtd);
if (err) {
dev_err(nfc->dev, "Error requesting IRQ!\n");
- goto err_clk;
+ goto err_disable_clk;
}
vf610_nfc_preinit_controller(nfc);
@@ -720,7 +720,7 @@ static int vf610_nfc_probe(struct platform_device *pdev)
/* first scan to find the device and get the page size */
err = nand_scan_ident(mtd, 1, NULL);
if (err)
- goto err_clk;
+ goto err_disable_clk;
vf610_nfc_init_controller(nfc);
@@ -732,20 +732,20 @@ static int vf610_nfc_probe(struct platform_device *pdev)
if (mtd->writesize + mtd->oobsize > PAGE_2K + OOB_MAX - 8) {
dev_err(nfc->dev, "Unsupported flash page size\n");
err = -ENXIO;
- goto err_clk;
+ goto err_disable_clk;
}
if (chip->ecc.mode == NAND_ECC_HW) {
if (mtd->writesize != PAGE_2K && mtd->oobsize < 64) {
dev_err(nfc->dev, "Unsupported flash with hwecc\n");
err = -ENXIO;
- goto err_clk;
+ goto err_disable_clk;
}
if (chip->ecc.size != mtd->writesize) {
dev_err(nfc->dev, "Step size needs to be page size\n");
err = -ENXIO;
- goto err_clk;
+ goto err_disable_clk;
}
/* Only 64 byte ECC layouts known */
@@ -765,7 +765,7 @@ static int vf610_nfc_probe(struct platform_device *pdev)
} else {
dev_err(nfc->dev, "Unsupported ECC strength\n");
err = -ENXIO;
- goto err_clk;
+ goto err_disable_clk;
}
chip->ecc.read_page = vf610_nfc_read_page;
@@ -777,14 +777,14 @@ static int vf610_nfc_probe(struct platform_device *pdev)
/* second phase scan */
err = nand_scan_tail(mtd);
if (err)
- goto err_clk;
+ goto err_disable_clk;
platform_set_drvdata(pdev, mtd);
/* Register device in MTD */
return mtd_device_register(mtd, NULL, 0);
-err_clk:
+err_disable_clk:
clk_disable_unprepare(nfc->clk);
return err;
}
--
2.7.4
vf610_nfc_probe() misses error handling of mtd_device_register().
Found by Linux Driver Verification project (linuxtesting.org).
Signed-off-by: Alexey Khoroshilov <[email protected]>
---
drivers/mtd/nand/vf610_nfc.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/mtd/nand/vf610_nfc.c b/drivers/mtd/nand/vf610_nfc.c
index 9cc5992e88c8..64fed3d9e3d4 100644
--- a/drivers/mtd/nand/vf610_nfc.c
+++ b/drivers/mtd/nand/vf610_nfc.c
@@ -782,8 +782,13 @@ static int vf610_nfc_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, mtd);
/* Register device in MTD */
- return mtd_device_register(mtd, NULL, 0);
+ err = mtd_device_register(mtd, NULL, 0);
+ if (err)
+ goto err_cleanup_nand;
+ return 0;
+err_cleanup_nand:
+ nand_cleanup(chip);
err_disable_clk:
clk_disable_unprepare(nfc->clk);
return err;
--
2.7.4
On 09.02.2018 23:28, Alexey Khoroshilov wrote:
> vf610_nfc_probe() misses error handling of mtd_device_register().
>
> Found by Linux Driver Verification project (linuxtesting.org).
>
> Signed-off-by: Alexey Khoroshilov <[email protected]>
Looks good to me, and seems to work fine, thanks for fixing this!
For the complete patchset:
Reviewed-by: Stefan Agner <[email protected]>
--
Stefan
> ---
> drivers/mtd/nand/vf610_nfc.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/mtd/nand/vf610_nfc.c b/drivers/mtd/nand/vf610_nfc.c
> index 9cc5992e88c8..64fed3d9e3d4 100644
> --- a/drivers/mtd/nand/vf610_nfc.c
> +++ b/drivers/mtd/nand/vf610_nfc.c
> @@ -782,8 +782,13 @@ static int vf610_nfc_probe(struct platform_device *pdev)
> platform_set_drvdata(pdev, mtd);
>
> /* Register device in MTD */
> - return mtd_device_register(mtd, NULL, 0);
> + err = mtd_device_register(mtd, NULL, 0);
> + if (err)
> + goto err_cleanup_nand;
> + return 0;
>
> +err_cleanup_nand:
> + nand_cleanup(chip);
> err_disable_clk:
> clk_disable_unprepare(nfc->clk);
> return err;
On Sat, 10 Feb 2018 01:28:33 +0300
Alexey Khoroshilov <[email protected]> wrote:
> vf610_nfc_probe() misses error handling of mtd_device_register()
> and contains unneeded of_node_put() on error path.
Applied the whole series.
Thanks,
Boris
>
> v2: Add nand_cleanup() to undone nand_scan_tail() as Boris Brezillon noted.
> v3: Rename error labels, remove of_node_put() per Boris Brezillon request.
> v4: Separate fix in to 3 patches.
>
> Alexey Khoroshilov (3):
> mtd: nand: vf610: remove the unnecessary of_node_put()
> mtd: nand: vf610: improve readability of error label
> mtd: nand: vf610: check mtd_device_register() return code
>
> drivers/mtd/nand/vf610_nfc.c | 29 ++++++++++++++++-------------
> 1 file changed, 16 insertions(+), 13 deletions(-)
>
--
Boris Brezillon, Bootlin (formerly Free Electrons)
Embedded Linux and Kernel engineering
http://bootlin.com