All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mtd: nand: vf610: fix error handling in vf610_nfc_probe()
@ 2017-12-22 21:43 Alexey Khoroshilov
  2017-12-22 21:57 ` Boris Brezillon
  0 siblings, 1 reply; 13+ messages in thread
From: Alexey Khoroshilov @ 2017-12-22 21:43 UTC (permalink / raw)
  To: Stefan Agner, Boris Brezillon
  Cc: Alexey Khoroshilov, Richard Weinberger, linux-mtd, linux-kernel,
	ldv-project

vf610_nfc_probe() misses error handling of mtd_device_register().

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
---
 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

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH] mtd: nand: vf610: fix error handling in vf610_nfc_probe()
  2017-12-22 21:43 [PATCH] mtd: nand: vf610: fix error handling in vf610_nfc_probe() Alexey Khoroshilov
@ 2017-12-22 21:57 ` Boris Brezillon
  2017-12-23 19:18   ` [PATCH v2] " Alexey Khoroshilov
  0 siblings, 1 reply; 13+ messages in thread
From: Boris Brezillon @ 2017-12-22 21:57 UTC (permalink / raw)
  To: Alexey Khoroshilov
  Cc: Stefan Agner, Richard Weinberger, linux-mtd, linux-kernel, ldv-project

On Sat, 23 Dec 2017 00:43:14 +0300
Alexey Khoroshilov <khoroshilov@ispras.ru> wrote:

> vf610_nfc_probe() misses error handling of mtd_device_register().
> 
> Found by Linux Driver Verification project (linuxtesting.org).
> 
> Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
> ---
>  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));

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v2] mtd: nand: vf610: fix error handling in vf610_nfc_probe()
  2017-12-22 21:57 ` Boris Brezillon
@ 2017-12-23 19:18   ` Alexey Khoroshilov
  2018-01-06  9:12     ` Boris Brezillon
  2018-01-06  9:25     ` Boris Brezillon
  0 siblings, 2 replies; 13+ messages in thread
From: Alexey Khoroshilov @ 2017-12-23 19:18 UTC (permalink / raw)
  To: Stefan Agner, Boris Brezillon
  Cc: Alexey Khoroshilov, Richard Weinberger, linux-mtd, linux-kernel,
	ldv-project

vf610_nfc_probe() misses error handling of mtd_device_register().

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
---
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

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH v2] mtd: nand: vf610: fix error handling in vf610_nfc_probe()
  2017-12-23 19:18   ` [PATCH v2] " Alexey Khoroshilov
@ 2018-01-06  9:12     ` Boris Brezillon
  2018-01-06  9:25     ` Boris Brezillon
  1 sibling, 0 replies; 13+ messages in thread
From: Boris Brezillon @ 2018-01-06  9:12 UTC (permalink / raw)
  To: Alexey Khoroshilov
  Cc: Stefan Agner, ldv-project, Richard Weinberger, linux-mtd, linux-kernel

On Sat, 23 Dec 2017 22:18:26 +0300
Alexey Khoroshilov <khoroshilov@ispras.ru> wrote:

> vf610_nfc_probe() misses error handling of mtd_device_register().
> 
> Found by Linux Driver Verification project (linuxtesting.org).
> 
> Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
> ---
> 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);

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2] mtd: nand: vf610: fix error handling in vf610_nfc_probe()
  2017-12-23 19:18   ` [PATCH v2] " Alexey Khoroshilov
  2018-01-06  9:12     ` Boris Brezillon
@ 2018-01-06  9:25     ` Boris Brezillon
  2018-01-26 22:32       ` [PATCH v3] " Alexey Khoroshilov
  1 sibling, 1 reply; 13+ messages in thread
From: Boris Brezillon @ 2018-01-06  9:25 UTC (permalink / raw)
  To: Alexey Khoroshilov
  Cc: Stefan Agner, ldv-project, Richard Weinberger, linux-mtd, linux-kernel

On Sat, 23 Dec 2017 22:18:26 +0300
Alexey Khoroshilov <khoroshilov@ispras.ru> wrote:

> vf610_nfc_probe() misses error handling of mtd_device_register().
> 
> Found by Linux Driver Verification project (linuxtesting.org).
> 
> Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
> ---
> 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);

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v3] mtd: nand: vf610: fix error handling in vf610_nfc_probe()
  2018-01-06  9:25     ` Boris Brezillon
@ 2018-01-26 22:32       ` Alexey Khoroshilov
  2018-01-30 13:11         ` Boris Brezillon
  0 siblings, 1 reply; 13+ messages in thread
From: Alexey Khoroshilov @ 2018-01-26 22:32 UTC (permalink / raw)
  To: Boris Brezillon
  Cc: Alexey Khoroshilov, Stefan Agner, Richard Weinberger, linux-mtd,
	linux-kernel, ldv-project

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 <khoroshilov@ispras.ru>
---
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

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH v3] mtd: nand: vf610: fix error handling in vf610_nfc_probe()
  2018-01-26 22:32       ` [PATCH v3] " Alexey Khoroshilov
@ 2018-01-30 13:11         ` Boris Brezillon
  2018-02-09 22:28           ` [PATCH v4 0/3] " Alexey Khoroshilov
  0 siblings, 1 reply; 13+ messages in thread
From: Boris Brezillon @ 2018-01-30 13:11 UTC (permalink / raw)
  To: Alexey Khoroshilov
  Cc: ldv-project, Richard Weinberger, linux-kernel, Stefan Agner, linux-mtd

On Sat, 27 Jan 2018 01:32:41 +0300
Alexey Khoroshilov <khoroshilov@ispras.ru> 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 <khoroshilov@ispras.ru>
> ---
> 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;
>  }

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v4 0/3] mtd: nand: vf610: fix error handling in vf610_nfc_probe()
  2018-01-30 13:11         ` Boris Brezillon
@ 2018-02-09 22:28           ` Alexey Khoroshilov
  2018-02-09 22:28             ` [PATCH v4 1/3] mtd: nand: vf610: remove the unnecessary of_node_put() Alexey Khoroshilov
                               ` (3 more replies)
  0 siblings, 4 replies; 13+ messages in thread
From: Alexey Khoroshilov @ 2018-02-09 22:28 UTC (permalink / raw)
  To: Boris Brezillon
  Cc: Alexey Khoroshilov, Stefan Agner, Richard Weinberger, linux-mtd,
	linux-kernel, ldv-project

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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v4 1/3] mtd: nand: vf610: remove the unnecessary of_node_put()
  2018-02-09 22:28           ` [PATCH v4 0/3] " Alexey Khoroshilov
@ 2018-02-09 22:28             ` Alexey Khoroshilov
  2018-02-09 22:28             ` [PATCH v4 2/3] mtd: nand: vf610: improve readability of error label Alexey Khoroshilov
                               ` (2 subsequent siblings)
  3 siblings, 0 replies; 13+ messages in thread
From: Alexey Khoroshilov @ 2018-02-09 22:28 UTC (permalink / raw)
  To: Boris Brezillon
  Cc: Alexey Khoroshilov, Stefan Agner, Richard Weinberger, linux-mtd,
	linux-kernel, ldv-project

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 <khoroshilov@ispras.ru>
---
 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

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v4 2/3] mtd: nand: vf610: improve readability of error label
  2018-02-09 22:28           ` [PATCH v4 0/3] " Alexey Khoroshilov
  2018-02-09 22:28             ` [PATCH v4 1/3] mtd: nand: vf610: remove the unnecessary of_node_put() Alexey Khoroshilov
@ 2018-02-09 22:28             ` Alexey Khoroshilov
  2018-02-09 22:28             ` [PATCH v4 3/3] mtd: nand: vf610: check mtd_device_register() return code Alexey Khoroshilov
  2018-02-12 21:31             ` [PATCH v4 0/3] mtd: nand: vf610: fix error handling in vf610_nfc_probe() Boris Brezillon
  3 siblings, 0 replies; 13+ messages in thread
From: Alexey Khoroshilov @ 2018-02-09 22:28 UTC (permalink / raw)
  To: Boris Brezillon
  Cc: Alexey Khoroshilov, Stefan Agner, Richard Weinberger, linux-mtd,
	linux-kernel, ldv-project

Use clearer error labels as Boris Brezillon suggested.

Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
---
 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

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v4 3/3] mtd: nand: vf610: check mtd_device_register() return code
  2018-02-09 22:28           ` [PATCH v4 0/3] " Alexey Khoroshilov
  2018-02-09 22:28             ` [PATCH v4 1/3] mtd: nand: vf610: remove the unnecessary of_node_put() Alexey Khoroshilov
  2018-02-09 22:28             ` [PATCH v4 2/3] mtd: nand: vf610: improve readability of error label Alexey Khoroshilov
@ 2018-02-09 22:28             ` Alexey Khoroshilov
  2018-02-10  9:43               ` Stefan Agner
  2018-02-12 21:31             ` [PATCH v4 0/3] mtd: nand: vf610: fix error handling in vf610_nfc_probe() Boris Brezillon
  3 siblings, 1 reply; 13+ messages in thread
From: Alexey Khoroshilov @ 2018-02-09 22:28 UTC (permalink / raw)
  To: Boris Brezillon
  Cc: Alexey Khoroshilov, Stefan Agner, Richard Weinberger, linux-mtd,
	linux-kernel, ldv-project

vf610_nfc_probe() misses error handling of mtd_device_register().

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
---
 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

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH v4 3/3] mtd: nand: vf610: check mtd_device_register() return code
  2018-02-09 22:28             ` [PATCH v4 3/3] mtd: nand: vf610: check mtd_device_register() return code Alexey Khoroshilov
@ 2018-02-10  9:43               ` Stefan Agner
  0 siblings, 0 replies; 13+ messages in thread
From: Stefan Agner @ 2018-02-10  9:43 UTC (permalink / raw)
  To: Alexey Khoroshilov
  Cc: Boris Brezillon, Richard Weinberger, linux-mtd, linux-kernel,
	ldv-project

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 <khoroshilov@ispras.ru>

Looks good to me, and seems to work fine, thanks for fixing this!

For the complete patchset:

Reviewed-by: Stefan Agner <stefan@agner.ch>

--
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;

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v4 0/3] mtd: nand: vf610: fix error handling in vf610_nfc_probe()
  2018-02-09 22:28           ` [PATCH v4 0/3] " Alexey Khoroshilov
                               ` (2 preceding siblings ...)
  2018-02-09 22:28             ` [PATCH v4 3/3] mtd: nand: vf610: check mtd_device_register() return code Alexey Khoroshilov
@ 2018-02-12 21:31             ` Boris Brezillon
  3 siblings, 0 replies; 13+ messages in thread
From: Boris Brezillon @ 2018-02-12 21:31 UTC (permalink / raw)
  To: Alexey Khoroshilov
  Cc: Boris Brezillon, ldv-project, Richard Weinberger, linux-kernel,
	Stefan Agner, linux-mtd

On Sat, 10 Feb 2018 01:28:33 +0300
Alexey Khoroshilov <khoroshilov@ispras.ru> 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

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2018-02-12 21:31 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-22 21:43 [PATCH] mtd: nand: vf610: fix error handling in vf610_nfc_probe() Alexey Khoroshilov
2017-12-22 21:57 ` Boris Brezillon
2017-12-23 19:18   ` [PATCH v2] " Alexey Khoroshilov
2018-01-06  9:12     ` Boris Brezillon
2018-01-06  9:25     ` Boris Brezillon
2018-01-26 22:32       ` [PATCH v3] " Alexey Khoroshilov
2018-01-30 13:11         ` Boris Brezillon
2018-02-09 22:28           ` [PATCH v4 0/3] " Alexey Khoroshilov
2018-02-09 22:28             ` [PATCH v4 1/3] mtd: nand: vf610: remove the unnecessary of_node_put() Alexey Khoroshilov
2018-02-09 22:28             ` [PATCH v4 2/3] mtd: nand: vf610: improve readability of error label Alexey Khoroshilov
2018-02-09 22:28             ` [PATCH v4 3/3] mtd: nand: vf610: check mtd_device_register() return code Alexey Khoroshilov
2018-02-10  9:43               ` Stefan Agner
2018-02-12 21:31             ` [PATCH v4 0/3] mtd: nand: vf610: fix error handling in vf610_nfc_probe() Boris Brezillon

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.