[PATCH v4 27/58] mtd: rawnand: technologic: retain open-handle state on removal
From: James Hilliard
Date: Fri Nov 13 2026 - 14:08:30 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.
Transfer flash-node ownership to the retained-chip helper.
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/technologic-nand-controller.c | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)
diff --git a/drivers/mtd/nand/raw/technologic-nand-controller.c b/drivers/mtd/nand/raw/technologic-nand-controller.c
index a4de53f954e5..98cf91136d0b 100644
--- a/drivers/mtd/nand/raw/technologic-nand-controller.c
+++ b/drivers/mtd/nand/raw/technologic-nand-controller.c
@@ -139,11 +139,13 @@ static int ts72xx_nand_probe(struct platform_device *pdev)
struct mtd_info *mtd;
int err;
- data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
+ data = kzalloc_obj(*data);
if (!data)
return -ENOMEM;
- nand_controller_init(&data->controller);
+ err = devm_nand_controller_init(&pdev->dev, &data->controller, data);
+ if (err)
+ return err;
data->controller.ops = &ts72xx_nand_ops;
data->chip.controller = &data->controller;
@@ -175,10 +177,17 @@ static int ts72xx_nand_probe(struct platform_device *pdev)
if (err)
goto err_handle_put;
- err = mtd_device_parse_register(mtd, NULL, NULL, NULL, 0);
+ err = nand_set_lifetime(&data->chip, NULL);
if (err)
goto err_clean_nand;
+ err = mtd_device_parse_register(mtd, NULL, NULL, NULL, 0);
+ if (err) {
+ nand_disconnect(&data->chip);
+ mtd_put_master(mtd);
+ goto err_handle_put;
+ }
+ fwnode_handle_put(child);
return 0;
err_clean_nand:
@@ -191,14 +200,13 @@ static int ts72xx_nand_probe(struct platform_device *pdev)
static void ts72xx_nand_remove(struct platform_device *pdev)
{
struct ts72xx_nand_data *data = platform_get_drvdata(pdev);
- struct fwnode_handle *fwnode = dev_fwnode(&pdev->dev);
struct nand_chip *chip = &data->chip;
int ret;
ret = mtd_device_unregister(nand_to_mtd(chip));
WARN_ON(ret);
- nand_cleanup(chip);
- fwnode_handle_put(fwnode);
+ nand_disconnect(chip);
+ mtd_put_master(nand_to_mtd(chip));
}
static const struct of_device_id ts72xx_id_table[] = {
--
2.53.0