Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mtd: rawnand: mtk: Fix init error path

Reviewing a series converting the for_each_chil_of_node() loops into
their _scoped variants made me realize there was no cleanup of the
already registered NAND devices upon error which may leak memory on
systems with more than a chip when this error occurs. We should call the
_nand_chips_cleanup() function when this happens.

Fixes: 1d6b1e464950 ("mtd: mediatek: driver for MTK Smart Device")
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Reviewed-by: Pratyush Yadav <pratyush@kernel.org>
Reviewed-by: Matthias Brugger <matthias.bgg@kernel.org>
Link: https://lore.kernel.org/linux-mtd/20240826153019.67106-2-miquel.raynal@bootlin.com

+3 -1
+3 -1
drivers/mtd/nand/raw/mtk_nand.c
··· 1453 1453 1454 1454 for_each_child_of_node_scoped(np, nand_np) { 1455 1455 ret = mtk_nfc_nand_chip_init(dev, nfc, nand_np); 1456 - if (ret) 1456 + if (ret) { 1457 + mtk_nfc_nand_chips_cleanup(nfc); 1457 1458 return ret; 1459 + } 1458 1460 } 1459 1461 1460 1462 return 0;