[PATCH v3 45/58] mtd: rawnand: sh_flctl: retain chip state across removal
From: James Hilliard
Date: Wed Nov 11 2026 - 20:51:57 EST
Unregister and disconnect the NAND chip before releasing the DMA
channel. Retain chip and controller storage until the last MTD reference
is dropped.
Run NAND cleanup during disconnection; the final core-owned put only
releases retained allocation and layout data.
Signed-off-by: James Hilliard <james.hilliard1@xxxxxxxxx>
---
drivers/mtd/nand/raw/sh_flctl.c | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)
diff --git a/drivers/mtd/nand/raw/sh_flctl.c b/drivers/mtd/nand/raw/sh_flctl.c
index 36ba5b3da3a0..b230f5ef448b 100644
--- a/drivers/mtd/nand/raw/sh_flctl.c
+++ b/drivers/mtd/nand/raw/sh_flctl.c
@@ -1119,9 +1119,14 @@ static int flctl_probe(struct platform_device *pdev)
int ret;
int irq;
- flctl = devm_kzalloc(&pdev->dev, sizeof(struct sh_flctl), GFP_KERNEL);
+ flctl = kzalloc_obj(*flctl);
if (!flctl)
return -ENOMEM;
+ nand = &flctl->chip;
+ nand->controller = &nand->legacy.dummy_controller;
+ ret = devm_nand_controller_init(&pdev->dev, nand->controller, flctl);
+ if (ret)
+ return ret;
flctl->reg = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
if (IS_ERR(flctl->reg))
@@ -1187,9 +1192,15 @@ static int flctl_probe(struct platform_device *pdev)
if (ret)
goto err_chip;
- ret = mtd_device_register(flctl_mtd, pdata->parts, pdata->nr_parts);
+ ret = nand_set_lifetime(nand, NULL);
if (ret)
goto cleanup_nand;
+ ret = mtd_device_register(flctl_mtd, pdata->parts, pdata->nr_parts);
+ if (ret) {
+ nand_disconnect(nand);
+ mtd_put_master(flctl_mtd);
+ goto err_chip;
+ }
return 0;
@@ -1207,11 +1218,12 @@ static void flctl_remove(struct platform_device *pdev)
struct nand_chip *chip = &flctl->chip;
int ret;
- flctl_release_dma(flctl);
ret = mtd_device_unregister(nand_to_mtd(chip));
WARN_ON(ret);
- nand_cleanup(chip);
+ nand_disconnect(chip);
+ flctl_release_dma(flctl);
pm_runtime_disable(&pdev->dev);
+ mtd_put_master(nand_to_mtd(chip));
}
static struct platform_driver flctl_driver = {
--
2.53.0