[PATCH v2 06/16] mtd: rawnand: fsl_elbc: fix probe function error path

Boris Brezillon boris.brezillon at bootlin.com
Tue Mar 27 00:56:37 PDT 2018


On Wed, 21 Mar 2018 14:01:47 +0100
Miquel Raynal <miquel.raynal at 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 at bootlin.com>
> ---
>  drivers/mtd/nand/raw/fsl_elbc_nand.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/mtd/nand/raw/fsl_elbc_nand.c b/drivers/mtd/nand/raw/fsl_elbc_nand.c
> index d28df991c73c..7a7cb60ec93c 100644
> --- a/drivers/mtd/nand/raw/fsl_elbc_nand.c
> +++ b/drivers/mtd/nand/raw/fsl_elbc_nand.c
> @@ -926,15 +926,20 @@ static int fsl_elbc_nand_probe(struct platform_device *pdev)
>  
>  	/* 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;
>  
>  	pr_info("eLBC 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_elbc_chip_remove(priv);

fsl_elbc_chip_remove() is already calling nand_release() (which
contains a call to nand_cleanup()), so we might experience double-free
issues if some of the fields are not re-initialized to NULL.

> +
>  	return ret;
>  }
>  



-- 
Boris Brezillon, Bootlin (formerly Free Electrons)
Embedded Linux and Kernel engineering
https://bootlin.com



More information about the linux-mtd mailing list