diff mbox series

[v2,07/16] mtd: rawnand: fsl_ifc: fix probe function error path

Message ID 20180321130157.9524-8-miquel.raynal@bootlin.com
State Changes Requested
Delegated to: Boris Brezillon
Headers show
Series Fix probe functions error path | expand

Commit Message

Miquel Raynal March 21, 2018, 1:01 p.m. UTC
An error after nand_scan_tail() should trigger a nand_cleanup().
The helper mtd_device_parse_register() returns an error code that should
be checked and nand_cleanup() called accordingly.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 drivers/mtd/nand/raw/fsl_ifc_nand.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Comments

Boris Brezillon March 27, 2018, 7:57 a.m. UTC | #1
On Wed, 21 Mar 2018 14:01:48 +0100
Miquel Raynal <miquel.raynal@bootlin.com> wrote:

> An error after nand_scan_tail() should trigger a nand_cleanup().
> The helper mtd_device_parse_register() returns an error code that should
> be checked and nand_cleanup() called accordingly.
> 
> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> ---
>  drivers/mtd/nand/raw/fsl_ifc_nand.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/mtd/nand/raw/fsl_ifc_nand.c b/drivers/mtd/nand/raw/fsl_ifc_nand.c
> index 7ca678f05ae3..6082528ec7f1 100644
> --- a/drivers/mtd/nand/raw/fsl_ifc_nand.c
> +++ b/drivers/mtd/nand/raw/fsl_ifc_nand.c
> @@ -1065,14 +1065,20 @@ static int fsl_ifc_nand_probe(struct platform_device *dev)
>  
>  	/* First look for RedBoot table or partitions on the command
>  	 * line, these take precedence over device tree information */
> -	mtd_device_parse_register(mtd, part_probe_types, NULL, NULL, 0);
> +	ret = mtd_device_parse_register(mtd, part_probe_types, NULL, NULL, 0);
> +	if (ret)
> +		goto cleanup_nand;
>  
>  	dev_info(priv->dev, "IFC NAND device at 0x%llx, bank %d\n",
>  		 (unsigned long long)res.start, priv->bank);
> +
>  	return 0;
>  
> +cleanup_nand:
> +	nand_cleanup(&priv->chip);
>  err:
>  	fsl_ifc_chip_remove(priv);
> +

Same as for the elbc patch: we might have double-free issues after this
change.

>  	return ret;
>  }
>
diff mbox series

Patch

diff --git a/drivers/mtd/nand/raw/fsl_ifc_nand.c b/drivers/mtd/nand/raw/fsl_ifc_nand.c
index 7ca678f05ae3..6082528ec7f1 100644
--- a/drivers/mtd/nand/raw/fsl_ifc_nand.c
+++ b/drivers/mtd/nand/raw/fsl_ifc_nand.c
@@ -1065,14 +1065,20 @@  static int fsl_ifc_nand_probe(struct platform_device *dev)
 
 	/* First look for RedBoot table or partitions on the command
 	 * line, these take precedence over device tree information */
-	mtd_device_parse_register(mtd, part_probe_types, NULL, NULL, 0);
+	ret = mtd_device_parse_register(mtd, part_probe_types, NULL, NULL, 0);
+	if (ret)
+		goto cleanup_nand;
 
 	dev_info(priv->dev, "IFC NAND device at 0x%llx, bank %d\n",
 		 (unsigned long long)res.start, priv->bank);
+
 	return 0;
 
+cleanup_nand:
+	nand_cleanup(&priv->chip);
 err:
 	fsl_ifc_chip_remove(priv);
+
 	return ret;
 }