Skip to content

Commit 81cb3be

Browse files
committed
mtd: rawnand: mtk: Factorize out the logic cleaning mtk chips
There are some un-freed resources in one of the error path which would benefit from a helper going through all the registered mtk chips one by one and perform all the necessary cleanup. This is precisely what the remove path does, so let's extract the logic in a helper. There is no functional change. Signed-off-by: Miquel Raynal <[email protected]> Reviewed-by: Pratyush Yadav <[email protected]> Reviewed-by: Matthias Brugger <[email protected]> Link: https://lore.kernel.org/linux-mtd/[email protected]
1 parent 9b3c395 commit 81cb3be

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

drivers/mtd/nand/raw/mtk_nand.c

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,6 +1429,23 @@ static int mtk_nfc_nand_chip_init(struct device *dev, struct mtk_nfc *nfc,
14291429
return 0;
14301430
}
14311431

1432+
static void mtk_nfc_nand_chips_cleanup(struct mtk_nfc *nfc)
1433+
{
1434+
struct mtk_nfc_nand_chip *mtk_chip;
1435+
struct nand_chip *chip;
1436+
int ret;
1437+
1438+
while (!list_empty(&nfc->chips)) {
1439+
mtk_chip = list_first_entry(&nfc->chips,
1440+
struct mtk_nfc_nand_chip, node);
1441+
chip = &mtk_chip->nand;
1442+
ret = mtd_device_unregister(nand_to_mtd(chip));
1443+
WARN_ON(ret);
1444+
nand_cleanup(chip);
1445+
list_del(&mtk_chip->node);
1446+
}
1447+
}
1448+
14321449
static int mtk_nfc_nand_chips_init(struct device *dev, struct mtk_nfc *nfc)
14331450
{
14341451
struct device_node *np = dev->of_node;
@@ -1567,20 +1584,8 @@ static int mtk_nfc_probe(struct platform_device *pdev)
15671584
static void mtk_nfc_remove(struct platform_device *pdev)
15681585
{
15691586
struct mtk_nfc *nfc = platform_get_drvdata(pdev);
1570-
struct mtk_nfc_nand_chip *mtk_chip;
1571-
struct nand_chip *chip;
1572-
int ret;
1573-
1574-
while (!list_empty(&nfc->chips)) {
1575-
mtk_chip = list_first_entry(&nfc->chips,
1576-
struct mtk_nfc_nand_chip, node);
1577-
chip = &mtk_chip->nand;
1578-
ret = mtd_device_unregister(nand_to_mtd(chip));
1579-
WARN_ON(ret);
1580-
nand_cleanup(chip);
1581-
list_del(&mtk_chip->node);
1582-
}
15831587

1588+
mtk_nfc_nand_chips_cleanup(nfc);
15841589
mtk_ecc_release(nfc->ecc);
15851590
}
15861591

0 commit comments

Comments
 (0)