]> git.itanic.dy.fi Git - linux-stable/commitdiff
mtd: rawnand: oxnas: Unregister all devices on error
authorMiquel Raynal <miquel.raynal@bootlin.com>
Tue, 19 May 2020 13:00:10 +0000 (15:00 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 22 Jul 2020 07:32:07 +0000 (09:32 +0200)
commit b60391eb17b2956ff2fc4c348e5a464da21ff9cb upstream.

On error, the oxnas probe path just frees the device which failed and
aborts the probe, leaving unreleased resources.

Fix this situation by calling mtd_device_unregister()/nand_cleanup()
on these.

Fixes: 668592492409 ("mtd: nand: Add OX820 NAND Support")
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20200519130035.1883-38-miquel.raynal@bootlin.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/mtd/nand/raw/oxnas_nand.c

index b9b0511f46006f0e481a62dab4509c0b937f6026..70286eef045bfbb3a46aeb9d656fb6b24cdd217a 100644 (file)
@@ -89,6 +89,7 @@ static int oxnas_nand_probe(struct platform_device *pdev)
        struct resource *res;
        int count = 0;
        int err = 0;
+       int i;
 
        /* Allocate memory for the device structure (and zero it) */
        oxnas = devm_kzalloc(&pdev->dev, sizeof(*oxnas),
@@ -168,6 +169,13 @@ static int oxnas_nand_probe(struct platform_device *pdev)
        nand_cleanup(chip);
 err_release_child:
        of_node_put(nand_np);
+
+       for (i = 0; i < oxnas->nchips; i++) {
+               chip = oxnas->chips[i];
+               WARN_ON(mtd_device_unregister(nand_to_mtd(chip)));
+               nand_cleanup(chip);
+       }
+
 err_clk_unprepare:
        clk_disable_unprepare(oxnas->clk);
        return err;