mtd: rawnand: docg4: fix the probe function error path
authorMiquel Raynal <miquel.raynal@bootlin.com>
Sun, 25 Feb 2018 22:09:14 +0000 (23:09 +0100)
committerMiquel Raynal <miquel.raynal@bootlin.com>
Wed, 18 Jul 2018 07:24:15 +0000 (09:24 +0200)
nand_release() should not be called on an MTD device that has not been
registered. While it should work thanks to the checks done in
mtd_device_unregister() it's a bad practice to cleanup/release
something that has not previously been initialized/allocated.

Rework the error path to follow this rule.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
drivers/mtd/nand/raw/docg4.c

index 1314aa99b9ab506e73c457b3c8c9b255f80ae9f6..bb96cb33cd6b6cfbd10fe36afb97ef6862c187e7 100644 (file)
@@ -1341,7 +1341,7 @@ static int __init probe_docg4(struct platform_device *pdev)
        nand = kzalloc(len, GFP_KERNEL);
        if (nand == NULL) {
                retval = -ENOMEM;
-               goto fail_unmap;
+               goto unmap;
        }
 
        mtd = nand_to_mtd(nand);
@@ -1357,7 +1357,7 @@ static int __init probe_docg4(struct platform_device *pdev)
        doc->bch = init_bch(DOCG4_M, DOCG4_T, DOCG4_PRIMITIVE_POLY);
        if (doc->bch == NULL) {
                retval = -EINVAL;
-               goto fail;
+               goto free_nand;
        }
 
        platform_set_drvdata(pdev, doc);
@@ -1366,30 +1366,32 @@ static int __init probe_docg4(struct platform_device *pdev)
        retval = read_id_reg(mtd);
        if (retval == -ENODEV) {
                dev_warn(dev, "No diskonchip G4 device found.\n");
-               goto fail;
+               goto free_bch;
        }
 
        retval = nand_scan_tail(mtd);
        if (retval)
-               goto fail;
+               goto free_bch;
 
        retval = read_factory_bbt(mtd);
        if (retval)
-               goto fail;
+               goto cleanup_nand;
 
        retval = mtd_device_parse_register(mtd, part_probes, NULL, NULL, 0);
        if (retval)
-               goto fail;
+               goto cleanup_nand;
 
        doc->mtd = mtd;
+
        return 0;
 
-fail:
-       nand_release(mtd); /* deletes partitions and mtd devices */
+cleanup_nand:
+       nand_cleanup(nand);
+free_bch:
        free_bch(doc->bch);
+free_nand:
        kfree(nand);
-
-fail_unmap:
+unmap:
        iounmap(virtadr);
 
        return retval;