[PATCH 26/58] mtd: rawnand: vf610: retain open-handle state on removal

From: James Hilliard

Date: Sat Nov 07 2026 - 15:15:07 EST


Keep chip metadata and controller storage alive until the final MTD
reference is released. Unregister and disconnect each published chip
before releasing the resources used by its hardware operations.

Keep managed register, IRQ and clock teardown after chip disconnection.

Signed-off-by: James Hilliard <james.hilliard1@xxxxxxxxx>
---
drivers/mtd/nand/raw/vf610_nfc.c | 22 ++++++++++++++++++----
1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/nand/raw/vf610_nfc.c b/drivers/mtd/nand/raw/vf610_nfc.c
index 9940681810cf..903a25c549d8 100644
--- a/drivers/mtd/nand/raw/vf610_nfc.c
+++ b/drivers/mtd/nand/raw/vf610_nfc.c
@@ -805,6 +805,11 @@ static const struct nand_controller_ops vf610_nfc_controller_ops = {

};

+static void vf610_nfc_release(struct nand_controller *controller)
+{
+ kfree(container_of(controller, struct vf610_nfc, base));
+}
+
static int vf610_nfc_probe(struct platform_device *pdev)
{
struct vf610_nfc *nfc;
@@ -813,9 +818,12 @@ static int vf610_nfc_probe(struct platform_device *pdev)
int err;
int irq;

- nfc = devm_kzalloc(&pdev->dev, sizeof(*nfc), GFP_KERNEL);
+ nfc = kzalloc_obj(*nfc);
if (!nfc)
return -ENOMEM;
+ err = devm_nand_controller_init(&pdev->dev, &nfc->base, vf610_nfc_release);
+ if (err)
+ return err;

nfc->dev = &pdev->dev;
chip = &nfc->chip;
@@ -873,7 +881,6 @@ static int vf610_nfc_probe(struct platform_device *pdev)

vf610_nfc_preinit_controller(nfc);

- nand_controller_init(&nfc->base);
nfc->base.ops = &vf610_nfc_controller_ops;
chip->controller = &nfc->base;

@@ -885,9 +892,15 @@ static int vf610_nfc_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, nfc);

/* Register device in MTD */
- err = mtd_device_register(mtd, NULL, 0);
+ err = nand_set_release(chip, NULL);
if (err)
goto err_cleanup_nand;
+ err = mtd_device_register(mtd, NULL, 0);
+ if (err) {
+ nand_disconnect(chip);
+ mtd_put_master(mtd);
+ return err;
+ }
return 0;

err_cleanup_nand:
@@ -903,7 +916,8 @@ static void vf610_nfc_remove(struct platform_device *pdev)

ret = mtd_device_unregister(nand_to_mtd(chip));
WARN_ON(ret);
- nand_cleanup(chip);
+ nand_disconnect(chip);
+ mtd_put_master(nand_to_mtd(chip));
}

#ifdef CONFIG_PM_SLEEP

--
2.53.0