* [PATCH 1/3] mtd: rawnand: qcom: parse boot partitions before registering MTD
2026-11-08 21:16 [PATCH 0/3] mtd: rawnand: qcom: unwind failed child initialization James Hilliard
@ 2026-11-08 21:16 ` James Hilliard
2026-11-08 21:16 ` [PATCH 2/3] mtd: rawnand: qcom: retain the BAM transaction if replacement fails James Hilliard
2026-11-08 21:16 ` [PATCH 3/3] mtd: rawnand: qcom: unwind registered chips on child probe failure James Hilliard
2 siblings, 0 replies; 4+ messages in thread
From: James Hilliard @ 2026-11-08 21:16 UTC (permalink / raw)
To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
Manivannan Sadhasivam, Christian Marangi, Sricharan R,
Md Sadre Alam, Boris Brezillon
Cc: linux-mtd, linux-arm-msm, linux-kernel, James Hilliard, stable
A boot-partition parsing error currently calls nand_cleanup() after the
MTD device has already been registered, leaving a published device backed
by freed chip resources. Registration can also invoke consumers before
the boot-partition layout is available.
Parse that layout after nand_scan() supplies the geometry but before
publishing the device. All failures then reach cleanup without leaving a
registered MTD behind.
Fixes: 862bdedd7f4b ("mtd: nand: raw: qcom_nandc: add support for unprotected spare data pages")
Cc: stable@vger.kernel.org
Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
---
drivers/mtd/nand/raw/qcom_nandc.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/mtd/nand/raw/qcom_nandc.c b/drivers/mtd/nand/raw/qcom_nandc.c
index 2d98f79b492d..f240d1effa04 100644
--- a/drivers/mtd/nand/raw/qcom_nandc.c
+++ b/drivers/mtd/nand/raw/qcom_nandc.c
@@ -2052,16 +2052,16 @@ static int qcom_nand_host_init_and_register(struct qcom_nand_controller *nandc,
if (ret)
return ret;
- ret = mtd_device_parse_register(mtd, probes, NULL, NULL, 0);
- if (ret)
- goto err;
-
if (nandc->props->use_codeword_fixup) {
ret = qcom_nand_host_parse_boot_partitions(nandc, host, dn);
if (ret)
goto err;
}
+ ret = mtd_device_parse_register(mtd, probes, NULL, NULL, 0);
+ if (ret)
+ goto err;
+
return 0;
err:
--
2.53.0
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH 2/3] mtd: rawnand: qcom: retain the BAM transaction if replacement fails
2026-11-08 21:16 [PATCH 0/3] mtd: rawnand: qcom: unwind failed child initialization James Hilliard
2026-11-08 21:16 ` [PATCH 1/3] mtd: rawnand: qcom: parse boot partitions before registering MTD James Hilliard
@ 2026-11-08 21:16 ` James Hilliard
2026-11-08 21:16 ` [PATCH 3/3] mtd: rawnand: qcom: unwind registered chips on child probe failure James Hilliard
2 siblings, 0 replies; 4+ messages in thread
From: James Hilliard @ 2026-11-08 21:16 UTC (permalink / raw)
To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
Manivannan Sadhasivam, Christian Marangi, Sricharan R,
Md Sadre Alam, Boris Brezillon
Cc: linux-mtd, linux-arm-msm, linux-kernel, James Hilliard, stable
Attaching a chip frees the controller's BAM transaction before allocating
one sized for its page geometry. Allocation failure leaves bam_txn NULL,
although later chip scans and previously registered chips still use that
shared transaction.
Allocate the replacement before freeing the old transaction. Restore the
old capacity on failure so the controller retains a usable transaction
for already initialized chips, including I/O during probe cleanup.
Fixes: ba7542eb2dd5 ("mtd: rawnand: qcom: fix memory corruption that causes panic")
Cc: stable@vger.kernel.org
Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
---
drivers/mtd/nand/raw/qcom_nandc.c | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/drivers/mtd/nand/raw/qcom_nandc.c b/drivers/mtd/nand/raw/qcom_nandc.c
index f240d1effa04..062fba9eaecc 100644
--- a/drivers/mtd/nand/raw/qcom_nandc.c
+++ b/drivers/mtd/nand/raw/qcom_nandc.c
@@ -1329,21 +1329,22 @@ static int qcom_nand_attach_chip(struct nand_chip *chip)
ecc->engine_type = NAND_ECC_ENGINE_TYPE_ON_HOST;
mtd_set_ooblayout(mtd, &qcom_nand_ooblayout_ops);
- /* Free the initially allocated BAM transaction for reading the ONFI params */
- if (nandc->props->supports_bam)
- qcom_free_bam_transaction(nandc);
-
- nandc->max_cwperpage = max_t(unsigned int, nandc->max_cwperpage,
- cwperpage);
-
/* Now allocate the BAM transaction based on updated max_cwperpage */
if (nandc->props->supports_bam) {
- nandc->bam_txn = qcom_alloc_bam_transaction(nandc);
- if (!nandc->bam_txn) {
+ unsigned int old_max_cwperpage = nandc->max_cwperpage;
+ struct bam_transaction *bam_txn;
+
+ nandc->max_cwperpage = max_t(unsigned int, old_max_cwperpage,
+ cwperpage);
+ bam_txn = qcom_alloc_bam_transaction(nandc);
+ if (!bam_txn) {
+ nandc->max_cwperpage = old_max_cwperpage;
dev_err(nandc->dev,
"failed to allocate bam transaction\n");
return -ENOMEM;
}
+ qcom_free_bam_transaction(nandc);
+ nandc->bam_txn = bam_txn;
}
/*
--
2.53.0
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH 3/3] mtd: rawnand: qcom: unwind registered chips on child probe failure
2026-11-08 21:16 [PATCH 0/3] mtd: rawnand: qcom: unwind failed child initialization James Hilliard
2026-11-08 21:16 ` [PATCH 1/3] mtd: rawnand: qcom: parse boot partitions before registering MTD James Hilliard
2026-11-08 21:16 ` [PATCH 2/3] mtd: rawnand: qcom: retain the BAM transaction if replacement fails James Hilliard
@ 2026-11-08 21:16 ` James Hilliard
2 siblings, 0 replies; 4+ messages in thread
From: James Hilliard @ 2026-11-08 21:16 UTC (permalink / raw)
To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
Manivannan Sadhasivam, Christian Marangi, Sricharan R,
Md Sadre Alam, Boris Brezillon
Cc: linux-mtd, linux-arm-msm, linux-kernel, James Hilliard, stable
qcom_probe_nand_devices() continues after a child initialization error,
allowing a later successful child to hide failures such as -ENOMEM or
-EPROBE_DEFER. If the last child fails, or allocating a subsequent host
fails, probe releases controller resources without unregistering chips
that were already published.
Fail probe on the first error from an enabled NAND child and propagate
that error. Share chip cleanup with removal and run it before releasing
DMA resources or disabling the controller clocks.
Fixes: 89f5127c4b0d ("mtd: nand: qcom: reorganize nand devices probing")
Cc: stable@vger.kernel.org
Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
---
drivers/mtd/nand/raw/qcom_nandc.c | 29 ++++++++++++++++++-----------
1 file changed, 18 insertions(+), 11 deletions(-)
diff --git a/drivers/mtd/nand/raw/qcom_nandc.c b/drivers/mtd/nand/raw/qcom_nandc.c
index 062fba9eaecc..14bb7f3d6c36 100644
--- a/drivers/mtd/nand/raw/qcom_nandc.c
+++ b/drivers/mtd/nand/raw/qcom_nandc.c
@@ -2085,7 +2085,7 @@ static int qcom_probe_nand_devices(struct qcom_nand_controller *nandc)
ret = qcom_nand_host_init_and_register(nandc, host, child);
if (ret) {
devm_kfree(dev, host);
- continue;
+ return ret;
}
list_add_tail(&host->node, &nandc->host_list);
@@ -2094,6 +2094,19 @@ static int qcom_probe_nand_devices(struct qcom_nand_controller *nandc)
return ret;
}
+static void qcom_nandc_cleanup_chips(struct qcom_nand_controller *nandc)
+{
+ struct qcom_nand_host *host, *tmp;
+ int ret;
+
+ list_for_each_entry_safe(host, tmp, &nandc->host_list, node) {
+ ret = mtd_device_unregister(nand_to_mtd(&host->chip));
+ WARN_ON(ret);
+ nand_cleanup(&host->chip);
+ list_del(&host->node);
+ }
+}
+
/* parse custom DT properties here */
static int qcom_nandc_parse_dt(struct platform_device *pdev)
{
@@ -2184,10 +2197,12 @@ static int qcom_nandc_probe(struct platform_device *pdev)
ret = qcom_probe_nand_devices(nandc);
if (ret)
- goto err_setup;
+ goto err_cleanup_chips;
return 0;
+err_cleanup_chips:
+ qcom_nandc_cleanup_chips(nandc);
err_setup:
qcom_nandc_unalloc(nandc);
err_nandc_alloc:
@@ -2204,16 +2219,8 @@ static void qcom_nandc_remove(struct platform_device *pdev)
{
struct qcom_nand_controller *nandc = platform_get_drvdata(pdev);
struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
- struct qcom_nand_host *host;
- struct nand_chip *chip;
- int ret;
- list_for_each_entry(host, &nandc->host_list, node) {
- chip = &host->chip;
- ret = mtd_device_unregister(nand_to_mtd(chip));
- WARN_ON(ret);
- nand_cleanup(chip);
- }
+ qcom_nandc_cleanup_chips(nandc);
qcom_nandc_unalloc(nandc);
--
2.53.0
^ permalink raw reply [flat|nested] 4+ messages in thread