[PATCH v2] mtd: rawnand: tegra: drain the IRQ before disabling the clock

James Hilliard james.hilliard1 at gmail.com
Sat Nov 28 23:56:38 PST 2026


On unbind or a late probe failure, the NAND clock is disabled before
devres releases the IRQ. The handler signals command and DMA completion
before its final write to the interrupt-status register, so it can still
access the controller after the clock has stopped.

Register the runtime PM cleanup before requesting the IRQ. Devres then
frees the exclusive IRQ and waits for any running handler before dropping
the PM reference, on both removal and probe failure.

Fixes: d7d9f8ec77fe ("mtd: rawnand: add NVIDIA Tegra NAND Flash controller driver")
Cc: stable at vger.kernel.org
Signed-off-by: James Hilliard <james.hilliard1 at gmail.com>
---
Changes in v2:
- Manage runtime PM teardown with devres so the IRQ is drained first
  without an explicit devm_free_irq(), as suggested by Miquèl.
- Link to v1: https://patch.msgid.link/20261108-submit-tegra-nand-irq-teardown-v1-v1-1-2c570ad4a22c@gmail.com
---
 drivers/mtd/nand/raw/tegra_nand.c | 43 +++++++++++++++++++--------------------
 1 file changed, 21 insertions(+), 22 deletions(-)

diff --git a/drivers/mtd/nand/raw/tegra_nand.c b/drivers/mtd/nand/raw/tegra_nand.c
index 199b3a8e552a..4f9c4aa75ed2 100644
--- a/drivers/mtd/nand/raw/tegra_nand.c
+++ b/drivers/mtd/nand/raw/tegra_nand.c
@@ -1143,6 +1143,15 @@ static int tegra_nand_chips_init(struct device *dev,
 	return 0;
 }
 
+static void tegra_nand_disable_pm(void *data)
+{
+	struct device *dev = data;
+
+	pm_runtime_put_sync_suspend(dev);
+	if (pm_runtime_force_suspend(dev))
+		pm_runtime_disable(dev);
+}
+
 static int tegra_nand_probe(struct platform_device *pdev)
 {
 	struct reset_control *rst;
@@ -1180,13 +1189,19 @@ static int tegra_nand_probe(struct platform_device *pdev)
 	 */
 	pm_runtime_enable(&pdev->dev);
 	err = pm_runtime_resume_and_get(&pdev->dev);
+	if (err) {
+		pm_runtime_disable(&pdev->dev);
+		return err;
+	}
+
+	err = devm_add_action_or_reset(&pdev->dev, tegra_nand_disable_pm, &pdev->dev);
 	if (err)
-		goto err_dis_pm;
+		return err;
 
 	err = reset_control_reset(rst);
 	if (err) {
 		dev_err(ctrl->dev, "Failed to reset HW: %d\n", err);
-		goto err_put_pm;
+		return err;
 	}
 
 	writel_relaxed(HWSTATUS_CMD_DEFAULT, ctrl->regs + HWSTATUS_CMD);
@@ -1197,31 +1212,18 @@ static int tegra_nand_probe(struct platform_device *pdev)
 	init_completion(&ctrl->dma_complete);
 
 	ctrl->irq = platform_get_irq(pdev, 0);
-	if (ctrl->irq < 0) {
-		err = ctrl->irq;
-		goto err_put_pm;
-	}
+	if (ctrl->irq < 0)
+		return ctrl->irq;
 	err = devm_request_irq(&pdev->dev, ctrl->irq, tegra_nand_irq, 0,
 			       dev_name(&pdev->dev), ctrl);
 	if (err) {
 		dev_err(ctrl->dev, "Failed to get IRQ: %d\n", err);
-		goto err_put_pm;
+		return err;
 	}
 
 	writel_relaxed(DMA_MST_CTRL_IS_DONE, ctrl->regs + DMA_MST_CTRL);
 
-	err = tegra_nand_chips_init(ctrl->dev, ctrl);
-	if (err)
-		goto err_put_pm;
-
-	return 0;
-
-err_put_pm:
-	pm_runtime_put_sync_suspend(ctrl->dev);
-	pm_runtime_force_suspend(ctrl->dev);
-err_dis_pm:
-	pm_runtime_disable(&pdev->dev);
-	return err;
+	return tegra_nand_chips_init(ctrl->dev, ctrl);
 }
 
 static void tegra_nand_remove(struct platform_device *pdev)
@@ -1233,9 +1235,6 @@ static void tegra_nand_remove(struct platform_device *pdev)
 	WARN_ON(mtd_device_unregister(mtd));
 
 	nand_cleanup(chip);
-
-	pm_runtime_put_sync_suspend(ctrl->dev);
-	pm_runtime_force_suspend(ctrl->dev);
 }
 
 static int __maybe_unused tegra_nand_runtime_resume(struct device *dev)

---
base-commit: ec1e844b9486302a488abc03ea918db60709766e
base-tree: git://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git nand/next
change-id: 20261107-submit-tegra-nand-irq-teardown-v1-60f649303b8c

Best regards,
--  
James Hilliard <james.hilliard1 at gmail.com>




More information about the linux-mtd mailing list