[PATCH v3 42/58] mtd: rawnand: au1550nd: retain chip state across removal
James Hilliard
james.hilliard1 at gmail.com
Wed Nov 11 17:28:21 PST 2026
Drain NAND access before unmapping the chip-select window, and retain
the chip and controller until the final MTD reference is released. Check
MTD registration errors so unsuccessful publication releases the same
ownership.
Run NAND cleanup during disconnection; the final core-owned put only
releases retained allocation and layout data.
Signed-off-by: James Hilliard <james.hilliard1 at gmail.com>
---
drivers/mtd/nand/raw/au1550nd.c | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/drivers/mtd/nand/raw/au1550nd.c b/drivers/mtd/nand/raw/au1550nd.c
index 01c2c8b191eb..83db1963c449 100644
--- a/drivers/mtd/nand/raw/au1550nd.c
+++ b/drivers/mtd/nand/raw/au1550nd.c
@@ -269,6 +269,9 @@ static int au1550nd_probe(struct platform_device *pdev)
ctx = kzalloc_obj(*ctx);
if (!ctx)
return -ENOMEM;
+ ret = devm_nand_controller_init(&pdev->dev, &ctx->controller, ctx);
+ if (ret)
+ return ret;
r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!r) {
@@ -302,7 +305,6 @@ static int au1550nd_probe(struct platform_device *pdev)
}
ctx->cs = cs;
- nand_controller_init(&ctx->controller);
ctx->controller.ops = &au1550nd_ops;
this->controller = &ctx->controller;
@@ -322,7 +324,17 @@ static int au1550nd_probe(struct platform_device *pdev)
goto out3;
}
- mtd_device_register(mtd, pd->parts, pd->num_parts);
+ ret = nand_set_lifetime(this, NULL);
+ if (ret) {
+ nand_cleanup(this);
+ goto out3;
+ }
+ ret = mtd_device_register(mtd, pd->parts, pd->num_parts);
+ if (ret) {
+ nand_disconnect(this);
+ mtd_put_master(mtd);
+ goto out3;
+ }
platform_set_drvdata(pdev, ctx);
@@ -333,7 +345,6 @@ static int au1550nd_probe(struct platform_device *pdev)
out2:
release_mem_region(r->start, resource_size(r));
out1:
- kfree(ctx);
return ret;
}
@@ -346,10 +357,10 @@ static void au1550nd_remove(struct platform_device *pdev)
ret = mtd_device_unregister(nand_to_mtd(chip));
WARN_ON(ret);
- nand_cleanup(chip);
+ nand_disconnect(chip);
iounmap(ctx->base);
release_mem_region(r->start, 0x1000);
- kfree(ctx);
+ mtd_put_master(nand_to_mtd(chip));
}
static struct platform_driver au1550nd_driver = {
--
2.53.0
More information about the linux-mtd
mailing list