[PATCH] mtd: rawnand: ndfc: clean up the NAND chip if registration fails
Cong Nguyen
congnt264 at gmail.com
Sun Nov 29 09:13:53 PST 2026
If mtd_device_register() fails in ndfc_chip_init(), the probe fails and
ndfc_remove() never runs, so nothing calls nand_cleanup() for the chip
that nand_scan() set up.
Call nand_cleanup() when mtd_device_register() fails.
Fixes: a808ad3b0d28 ("[MTD] [NAND] ndfc driver")
Signed-off-by: Cong Nguyen <congnt264 at gmail.com>
---
drivers/mtd/nand/raw/ndfc.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/mtd/nand/raw/ndfc.c b/drivers/mtd/nand/raw/ndfc.c
index d7b119028a71..9f9d124eb0e5 100644
--- a/drivers/mtd/nand/raw/ndfc.c
+++ b/drivers/mtd/nand/raw/ndfc.c
@@ -174,6 +174,8 @@ static int ndfc_chip_init(struct ndfc_controller *ndfc,
goto err;
ret = mtd_device_register(mtd, NULL, 0);
+ if (ret)
+ nand_cleanup(chip);
err:
of_node_put(flash_np);
--
2.25.1
More information about the linux-mtd
mailing list