[PATCH v2 2/4] mtd: rawnand: qcom: retain the BAM transaction if replacement fails
James Hilliard
james.hilliard1 at gmail.com
Sun Nov 8 14:42:09 PST 2026
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 at vger.kernel.org
Signed-off-by: James Hilliard <james.hilliard1 at 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
More information about the linux-mtd
mailing list