[PATCH 43/58] mtd: rawnand: sharpsl: retain chip state across removal
James Hilliard
james.hilliard1 at gmail.com
Sat Nov 7 02:16:40 PST 2026
Separate chip-select unmapping from chip storage reclamation.
Outstanding MTD references retain the scanned chip and layout metadata
after removal; new hardware operations fail once the chip is
disconnected.
Signed-off-by: James Hilliard <james.hilliard1 at gmail.com>
---
drivers/mtd/nand/raw/sharpsl.c | 25 ++++++++++++++++++-------
1 file changed, 18 insertions(+), 7 deletions(-)
diff --git a/drivers/mtd/nand/raw/sharpsl.c b/drivers/mtd/nand/raw/sharpsl.c
index 4154ab74f169..1ffd2b210d20 100644
--- a/drivers/mtd/nand/raw/sharpsl.c
+++ b/drivers/mtd/nand/raw/sharpsl.c
@@ -114,6 +114,11 @@ static const struct nand_controller_ops sharpsl_ops = {
.attach_chip = sharpsl_attach_chip,
};
+static void sharpsl_nand_release(struct nand_controller *controller)
+{
+ kfree(container_of(controller, struct sharpsl_nand, controller));
+}
+
/*
* Main initialization routine
*/
@@ -135,6 +140,9 @@ static int sharpsl_nand_probe(struct platform_device *pdev)
sharpsl = kzalloc_obj(struct sharpsl_nand);
if (!sharpsl)
return -ENOMEM;
+ err = devm_nand_controller_init(&pdev->dev, &sharpsl->controller, sharpsl_nand_release);
+ if (err)
+ return err;
r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!r) {
@@ -154,7 +162,6 @@ static int sharpsl_nand_probe(struct platform_device *pdev)
/* Get pointer to private data */
this = (struct nand_chip *)(&sharpsl->chip);
- nand_controller_init(&sharpsl->controller);
sharpsl->controller.ops = &sharpsl_ops;
this->controller = &sharpsl->controller;
@@ -188,10 +195,16 @@ static int sharpsl_nand_probe(struct platform_device *pdev)
/* Register the partitions */
mtd->name = "sharpsl-nand";
- err = mtd_device_parse_register(mtd, data->part_parsers, NULL,
- data->partitions, data->nr_partitions);
+ err = nand_set_release(this, NULL);
if (err)
goto err_add;
+ err = mtd_device_parse_register(mtd, data->part_parsers, NULL,
+ data->partitions, data->nr_partitions);
+ if (err) {
+ nand_disconnect(this);
+ mtd_put_master(mtd);
+ goto err_scan;
+ }
/* Return happy */
return 0;
@@ -203,7 +216,6 @@ static int sharpsl_nand_probe(struct platform_device *pdev)
iounmap(sharpsl->io);
err_ioremap:
err_get_res:
- kfree(sharpsl);
return err;
}
@@ -221,12 +233,11 @@ static void sharpsl_nand_remove(struct platform_device *pdev)
WARN_ON(ret);
/* Release resources */
- nand_cleanup(chip);
+ nand_disconnect(chip);
iounmap(sharpsl->io);
- /* Free the driver's structure */
- kfree(sharpsl);
+ mtd_put_master(nand_to_mtd(chip));
}
static struct platform_driver sharpsl_nand_driver = {
--
2.53.0
More information about the linux-mtd
mailing list