Message ID | 20180321130157.9524-7-miquel.raynal@bootlin.com |
---|---|
State | Changes Requested |
Delegated to: | Boris Brezillon |
Headers | show |
Series | Fix probe functions error path | expand |
On Wed, 21 Mar 2018 14:01:47 +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_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; > } >
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); + return ret; }
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_elbc_nand.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)