Commit 6d7fea22 authored by Samuel Holland's avatar Samuel Holland Committed by Miquel Raynal
Browse files

mtd: rawnand: sunxi: Clean up chips after failed init



If a chip fails to initialize, we need to clean up any chips that were
already initialized/registered.

Fixes: 1fef62c1 ("mtd: nand: add sunxi NAND flash controller support")
Signed-off-by: default avatarSamuel Holland <samuel@sholland.org>
Signed-off-by: default avatarMiquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20221229181526.53766-2-samuel@sholland.org
parent 68c18dae
Loading
Loading
Loading
Loading
+20 −19
Original line number Diff line number Diff line
@@ -1950,6 +1950,25 @@ static const struct nand_controller_ops sunxi_nand_controller_ops = {
	.exec_op = sunxi_nfc_exec_op,
};

static void sunxi_nand_chips_cleanup(struct sunxi_nfc *nfc)
{
	struct sunxi_nand_chip *sunxi_nand;
	struct nand_chip *chip;
	int ret;

	while (!list_empty(&nfc->chips)) {
		sunxi_nand = list_first_entry(&nfc->chips,
					      struct sunxi_nand_chip,
					      node);
		chip = &sunxi_nand->nand;
		ret = mtd_device_unregister(nand_to_mtd(chip));
		WARN_ON(ret);
		nand_cleanup(chip);
		sunxi_nand_ecc_cleanup(sunxi_nand);
		list_del(&sunxi_nand->node);
	}
}

static int sunxi_nand_chip_init(struct device *dev, struct sunxi_nfc *nfc,
				struct device_node *np)
{
@@ -2053,6 +2072,7 @@ static int sunxi_nand_chips_init(struct device *dev, struct sunxi_nfc *nfc)
		ret = sunxi_nand_chip_init(dev, nfc, nand_np);
		if (ret) {
			of_node_put(nand_np);
			sunxi_nand_chips_cleanup(nfc);
			return ret;
		}
	}
@@ -2060,25 +2080,6 @@ static int sunxi_nand_chips_init(struct device *dev, struct sunxi_nfc *nfc)
	return 0;
}

static void sunxi_nand_chips_cleanup(struct sunxi_nfc *nfc)
{
	struct sunxi_nand_chip *sunxi_nand;
	struct nand_chip *chip;
	int ret;

	while (!list_empty(&nfc->chips)) {
		sunxi_nand = list_first_entry(&nfc->chips,
					      struct sunxi_nand_chip,
					      node);
		chip = &sunxi_nand->nand;
		ret = mtd_device_unregister(nand_to_mtd(chip));
		WARN_ON(ret);
		nand_cleanup(chip);
		sunxi_nand_ecc_cleanup(sunxi_nand);
		list_del(&sunxi_nand->node);
	}
}

static int sunxi_nfc_dma_init(struct sunxi_nfc *nfc, struct resource *r)
{
	int ret;