From: Paul Cercueil <paul@crapouillou.net>
To: James Hilliard <james.hilliard1@gmail.com>,
Miquel Raynal <miquel.raynal@bootlin.com>,
Richard Weinberger <richard@nod.at>,
Vignesh Raghavendra <vigneshr@ti.com>
Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Harvey Hunt <harveyhuntnexus@gmail.com>,
linux-mips@vger.kernel.org
Subject: Re: [PATCH v4 50/58] mtd: rawnand: ingenic: retain chip state across removal
Date: Tue, 17 Nov 2026 11:29:25 +0100 [thread overview]
Message-ID: <edb4f1ae93fff1bea9380dc7fb1d2c8f2570bb67.camel@crapouillou.net> (raw)
In-Reply-To: <20261113-submit-rawnand-retained-handle-lifetime-v1-v4-50-556b1d7c6221@gmail.com>
Hi James,
I tried to apply on top of mtd/next but it does not apply cleanly.
So what base are you using?
Le vendredi 13 novembre 2026 à 11:15 -0700, James Hilliard a écrit :
> Unregister and disconnect all chips before releasing the ECC provider.
> Retain each chip and its shared controller until the final MTD put,
> while releasing hardware resources during device removal.
>
> Run NAND cleanup during disconnection; the final core-owned put only
> releases retained allocation and layout data.
>
> Cc: Harvey Hunt <harveyhuntnexus@gmail.com>
> Cc: linux-mips@vger.kernel.org
> Cc: Paul Cercueil <paul@crapouillou.net>
> Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
> ---
> drivers/mtd/nand/raw/ingenic/ingenic_nand_drv.c | 39 +++++++++++++++++-------
> -
> 1 file changed, 27 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/mtd/nand/raw/ingenic/ingenic_nand_drv.c
> b/drivers/mtd/nand/raw/ingenic/ingenic_nand_drv.c
> index bdda06ae0d72..2818ffe76796 100644
> --- a/drivers/mtd/nand/raw/ingenic/ingenic_nand_drv.c
> +++ b/drivers/mtd/nand/raw/ingenic/ingenic_nand_drv.c
> @@ -368,7 +368,7 @@ static int ingenic_nand_init_chip(struct platform_device
> *pdev,
> if (IS_ERR(cs->base))
> return PTR_ERR(cs->base);
>
> - nand = devm_kzalloc(dev, sizeof(*nand), GFP_KERNEL);
> + nand = kzalloc_obj(*nand);
> if (!nand)
> return -ENOMEM;
>
> @@ -377,7 +377,7 @@ static int ingenic_nand_init_chip(struct platform_device
> *pdev,
> if (IS_ERR(nand->busy_gpio)) {
> ret = PTR_ERR(nand->busy_gpio);
> dev_err(dev, "failed to request busy GPIO: %d\n", ret);
> - return ret;
> + goto free_chip;
> }
>
> nand->wp_gpio = devm_gpiod_get_optional(dev, "wp", GPIOD_OUT_LOW);
> @@ -385,15 +385,17 @@ static int ingenic_nand_init_chip(struct platform_device
> *pdev,
> if (IS_ERR(nand->wp_gpio)) {
> ret = PTR_ERR(nand->wp_gpio);
> dev_err(dev, "failed to request WP GPIO: %d\n", ret);
> - return ret;
> + goto free_chip;
> }
>
> chip = &nand->chip;
> mtd = nand_to_mtd(chip);
> mtd->name = devm_kasprintf(dev, GFP_KERNEL, "%s.%d", dev_name(dev),
> cs->bank);
> - if (!mtd->name)
> - return -ENOMEM;
> + if (!mtd->name) {
> + ret = -ENOMEM;
> + goto free_chip;
> + }
> mtd->parent_dev = dev;
>
> chip->options = NAND_NO_SUBPAGE_WRITE;
> @@ -404,17 +406,27 @@ static int ingenic_nand_init_chip(struct platform_device
> *pdev,
> chip->controller->ops = &ingenic_nand_controller_ops;
> ret = nand_scan(chip, 1);
> if (ret)
> - return ret;
> + goto free_chip;
Blank line here
> + ret = nand_set_lifetime(chip, to_ingenic_nand(nand_to_mtd(chip)));
This is quite convoluted, just do nand_set_lifetime(chip, nand);
> + if (ret) {
> + nand_cleanup(chip);
> + goto free_chip;
> + }
>
> ret = mtd_device_register(mtd, NULL, 0);
> if (ret) {
> - nand_cleanup(chip);
> + nand_disconnect(chip);
> + mtd_put_master(mtd);
> return ret;
> }
>
> list_add_tail(&nand->chip_list, &nfc->chips);
>
> return 0;
> +
> +free_chip:
> + kfree(nand);
> + return ret;
> }
>
> static void ingenic_nand_cleanup_chips(struct ingenic_nfc *nfc)
> @@ -429,8 +441,9 @@ static void ingenic_nand_cleanup_chips(struct ingenic_nfc
> *nfc)
> chip = &ingenic_chip->chip;
> ret = mtd_device_unregister(nand_to_mtd(chip));
> WARN_ON(ret);
> - nand_cleanup(chip);
> + nand_disconnect(chip);
> list_del(&ingenic_chip->chip_list);
> + mtd_put_master(nand_to_mtd(chip));
> }
> }
>
> @@ -474,9 +487,12 @@ static int ingenic_nand_probe(struct platform_device
> *pdev)
> return -ENODEV;
> }
>
> - nfc = devm_kzalloc(dev, struct_size(nfc, cs, num_banks), GFP_KERNEL);
> + nfc = kzalloc(struct_size(nfc, cs, num_banks), GFP_KERNEL);
> if (!nfc)
> return -ENOMEM;
Blank line here.
Cheers,
-Paul
> + ret = devm_nand_controller_init(dev, &nfc->controller, nfc);
> + if (ret)
> + return ret;
>
> nfc->soc_info = device_get_match_data(dev);
> if (!nfc->soc_info)
> @@ -493,7 +509,6 @@ static int ingenic_nand_probe(struct platform_device
> *pdev)
> nfc->dev = dev;
> nfc->num_banks = num_banks;
>
> - nand_controller_init(&nfc->controller);
> INIT_LIST_HEAD(&nfc->chips);
>
> ret = ingenic_nand_init_chips(nfc, pdev);
> @@ -511,10 +526,10 @@ static void ingenic_nand_remove(struct platform_device
> *pdev)
> {
> struct ingenic_nfc *nfc = platform_get_drvdata(pdev);
>
> + ingenic_nand_cleanup_chips(nfc);
> +
> if (nfc->ecc)
> ingenic_ecc_release(nfc->ecc);
> -
> - ingenic_nand_cleanup_chips(nfc);
> }
>
> static const struct jz_soc_info jz4740_soc_info = {
next prev parent reply other threads:[~2026-11-17 10:29 UTC|newest]
Thread overview: 61+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-13 18:14 [PATCH v4 00/58] mtd: rawnand: retain chip and controller " James Hilliard
2026-11-13 18:14 ` [PATCH v4 01/58] nvmem: disconnect provider callbacks before unregister returns James Hilliard
2026-11-13 18:14 ` [PATCH v4 02/58] mtd: acquire an MTD handle from a referenced class device James Hilliard
2026-11-13 18:14 ` [PATCH v4 03/58] mtd: separate class devices from retained backing objects James Hilliard
2026-11-13 18:14 ` [PATCH v4 04/58] mtd: retain virtual concatenations across component removal James Hilliard
2026-11-13 18:14 ` [PATCH v4 05/58] mtd: rawnand: separate hardware disconnection from cleanup James Hilliard
2026-11-13 18:14 ` [PATCH v4 06/58] mtd: rawnand: share retained chip and controller ownership James Hilliard
2026-11-13 18:14 ` [PATCH v4 07/58] mtd: rawnand: sunxi: retain chip state until the final MTD put James Hilliard
2026-11-13 18:14 ` [PATCH v4 08/58] mtd: rawnand: plat_nand: retain open-handle state on removal James Hilliard
2026-11-13 18:14 ` [PATCH v4 09/58] mtd: rawnand: gpio: " James Hilliard
2026-11-13 18:14 ` [PATCH v4 10/58] mtd: rawnand: stm32_fmc2: " James Hilliard
2026-11-13 18:14 ` [PATCH v4 11/58] mtd: rawnand: denali: retain chips across controller removal James Hilliard
2026-11-13 18:14 ` [PATCH v4 12/58] mtd: rawnand: arasan: " James Hilliard
2026-11-13 18:14 ` [PATCH v4 13/58] mtd: rawnand: mxic: retain open-handle state on removal James Hilliard
2026-11-13 18:14 ` [PATCH v4 14/58] mtd: rawnand: intel: " James Hilliard
2026-11-13 18:14 ` [PATCH v4 15/58] mtd: rawnand: tegra: " James Hilliard
2026-11-13 18:14 ` [PATCH v4 16/58] mtd: rawnand: mtk: retain chips across controller removal James Hilliard
2026-11-13 18:14 ` [PATCH v4 17/58] mtd: rawnand: rockchip: " James Hilliard
2026-11-13 18:14 ` [PATCH v4 18/58] mtd: rawnand: atmel: " James Hilliard
2026-11-13 18:14 ` [PATCH v4 19/58] mtd: rawnand: orion: retain open-handle state on removal James Hilliard
2026-11-13 18:14 ` [PATCH v4 20/58] mtd: rawnand: socrates: " James Hilliard
2026-11-13 18:14 ` [PATCH v4 21/58] mtd: rawnand: fsl_upm: " James Hilliard
2026-11-13 18:14 ` [PATCH v4 22/58] mtd: rawnand: pasemi: " James Hilliard
2026-11-13 18:14 ` [PATCH v4 23/58] mtd: rawnand: ams-delta: " James Hilliard
2026-11-13 18:14 ` [PATCH v4 24/58] mtd: rawnand: xway: " James Hilliard
2026-11-13 18:14 ` [PATCH v4 25/58] mtd: rawnand: hisi504: " James Hilliard
2026-11-13 18:14 ` [PATCH v4 26/58] mtd: rawnand: vf610: " James Hilliard
2026-11-13 18:14 ` [PATCH v4 27/58] mtd: rawnand: technologic: " James Hilliard
2026-11-13 18:14 ` [PATCH v4 28/58] mtd: rawnand: loongson: " James Hilliard
2026-11-13 18:14 ` [PATCH v4 29/58] mtd: rawnand: ma35d1: " James Hilliard
2026-11-13 18:14 ` [PATCH v4 30/58] mtd: rawnand: pl35x: " James Hilliard
2026-11-13 18:14 ` [PATCH v4 31/58] mtd: rawnand: mxc: " James Hilliard
2026-11-13 18:14 ` [PATCH v4 32/58] mtd: rawnand: fsmc: " James Hilliard
2026-11-13 18:14 ` [PATCH v4 33/58] mtd: rawnand: gpmi: " James Hilliard
2026-11-13 18:14 ` [PATCH v4 34/58] mtd: rawnand: omap2: " James Hilliard
2026-11-13 18:14 ` [PATCH v4 35/58] mtd: rawnand: marvell: " James Hilliard
2026-11-13 18:14 ` [PATCH v4 36/58] mtd: rawnand: renesas: " James Hilliard
2026-11-13 20:01 ` Wolfram Sang
2026-11-13 18:14 ` [PATCH v4 37/58] mtd: rawnand: meson: " James Hilliard
2026-11-13 18:14 ` [PATCH v4 38/58] mtd: rawnand: cadence: " James Hilliard
2026-11-13 18:14 ` [PATCH v4 39/58] mtd: rawnand: qcom: " James Hilliard
2026-11-13 18:14 ` [PATCH v4 40/58] mtd: rawnand: cafe: " James Hilliard
2026-11-13 18:14 ` [PATCH v4 41/58] mtd: rawnand: brcmnand: " James Hilliard
2026-11-13 18:14 ` [PATCH v4 42/58] mtd: rawnand: au1550nd: retain chip state across removal James Hilliard
2026-11-13 18:14 ` [PATCH v4 43/58] mtd: rawnand: sharpsl: " James Hilliard
2026-11-13 18:15 ` [PATCH v4 44/58] mtd: rawnand: davinci: " James Hilliard
2026-11-13 18:15 ` [PATCH v4 45/58] mtd: rawnand: sh_flctl: " James Hilliard
2026-11-13 18:15 ` [PATCH v4 46/58] mtd: rawnand: lpc32xx_slc: " James Hilliard
2026-11-13 18:15 ` [PATCH v4 47/58] mtd: rawnand: lpc32xx_mlc: " James Hilliard
2026-11-13 18:15 ` [PATCH v4 48/58] mtd: rawnand: ndfc: " James Hilliard
2026-11-13 18:15 ` [PATCH v4 49/58] mtd: rawnand: txx9ndfmc: " James Hilliard
2026-11-13 18:15 ` [PATCH v4 50/58] mtd: rawnand: ingenic: " James Hilliard
2026-11-17 10:29 ` Paul Cercueil [this message]
2026-11-13 18:15 ` [PATCH v4 51/58] mtd: rawnand: mpc5121: " James Hilliard
2026-11-13 18:15 ` [PATCH v4 52/58] mtd: rawnand: bcm47xxnflash: " James Hilliard
2026-11-13 18:15 ` [PATCH v4 53/58] mtd: rawnand: fsl_elbc: " James Hilliard
2026-11-13 18:15 ` [PATCH v4 54/58] mtd: rawnand: fsl_ifc: " James Hilliard
2026-11-13 18:15 ` [PATCH v4 55/58] mtd: rawnand: r852: " James Hilliard
2026-11-13 18:15 ` [PATCH v4 56/58] mtd: rawnand: nandsim: " James Hilliard
2026-11-13 18:15 ` [PATCH v4 57/58] mtd: rawnand: cs553x: " James Hilliard
2026-11-13 18:15 ` [PATCH v4 58/58] mtd: rawnand: diskonchip: " James Hilliard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=edb4f1ae93fff1bea9380dc7fb1d2c8f2570bb67.camel@crapouillou.net \
--to=paul@crapouillou.net \
--cc=gregkh@linuxfoundation.org \
--cc=harveyhuntnexus@gmail.com \
--cc=james.hilliard1@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mips@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=miquel.raynal@bootlin.com \
--cc=richard@nod.at \
--cc=vigneshr@ti.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®