Commit 8604e634 authored by Miquel Raynal's avatar Miquel Raynal

mtd: rawnand: docg4: fix the probe function error path

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: default avatarMiquel Raynal <miquel.raynal@bootlin.com>
parent 1dfac31a
...@@ -1341,7 +1341,7 @@ static int __init probe_docg4(struct platform_device *pdev) ...@@ -1341,7 +1341,7 @@ static int __init probe_docg4(struct platform_device *pdev)
nand = kzalloc(len, GFP_KERNEL); nand = kzalloc(len, GFP_KERNEL);
if (nand == NULL) { if (nand == NULL) {
retval = -ENOMEM; retval = -ENOMEM;
goto fail_unmap; goto unmap;
} }
mtd = nand_to_mtd(nand); mtd = nand_to_mtd(nand);
...@@ -1357,7 +1357,7 @@ static int __init probe_docg4(struct platform_device *pdev) ...@@ -1357,7 +1357,7 @@ static int __init probe_docg4(struct platform_device *pdev)
doc->bch = init_bch(DOCG4_M, DOCG4_T, DOCG4_PRIMITIVE_POLY); doc->bch = init_bch(DOCG4_M, DOCG4_T, DOCG4_PRIMITIVE_POLY);
if (doc->bch == NULL) { if (doc->bch == NULL) {
retval = -EINVAL; retval = -EINVAL;
goto fail; goto free_nand;
} }
platform_set_drvdata(pdev, doc); platform_set_drvdata(pdev, doc);
...@@ -1366,30 +1366,32 @@ static int __init probe_docg4(struct platform_device *pdev) ...@@ -1366,30 +1366,32 @@ static int __init probe_docg4(struct platform_device *pdev)
retval = read_id_reg(mtd); retval = read_id_reg(mtd);
if (retval == -ENODEV) { if (retval == -ENODEV) {
dev_warn(dev, "No diskonchip G4 device found.\n"); dev_warn(dev, "No diskonchip G4 device found.\n");
goto fail; goto free_bch;
} }
retval = nand_scan_tail(mtd); retval = nand_scan_tail(mtd);
if (retval) if (retval)
goto fail; goto free_bch;
retval = read_factory_bbt(mtd); retval = read_factory_bbt(mtd);
if (retval) if (retval)
goto fail; goto cleanup_nand;
retval = mtd_device_parse_register(mtd, part_probes, NULL, NULL, 0); retval = mtd_device_parse_register(mtd, part_probes, NULL, NULL, 0);
if (retval) if (retval)
goto fail; goto cleanup_nand;
doc->mtd = mtd; doc->mtd = mtd;
return 0; return 0;
fail: cleanup_nand:
nand_release(mtd); /* deletes partitions and mtd devices */ nand_cleanup(nand);
free_bch:
free_bch(doc->bch); free_bch(doc->bch);
free_nand:
kfree(nand); kfree(nand);
unmap:
fail_unmap:
iounmap(virtadr); iounmap(virtadr);
return retval; return retval;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment