[PATCH v2 2/3] mtd: rawnand: vf610_nfc: keep a timed-out command from completing the next one
From: Mehmet Fide
Date: Sat Nov 14 2026 - 14:21:00 EST
From: Mehmet Fide <mehmet.fide@xxxxxxxxxxxxxxxxxx>
A command that timed out can still finish later. Its interrupt then
completes cmd_done and leaves NFC_ISR[IDLE] set, so the next command
returns before the controller is done: the completion is already done
or, if only the completion is reinitialized, enabling the idle interrupt
raises it again at once.
On a timeout, disable the idle interrupt and wait for a running handler
to return. Before a command is started, clear the status flags and
reinitialize the completion.
Fixes: 456930d80a2d ("mtd: nand: vf610_nfc: Freescale NFC for VF610, MPC5125 and others")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Mehmet Fide <mehmet.fide@xxxxxxxxxxxxxxxxxx>
---
Applies as is down to 6.6.y. 6.1.y and older differ in the probe context
around platform_get_irq(), I can send a backport for those.
drivers/mtd/nand/raw/vf610_nfc.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/drivers/mtd/nand/raw/vf610_nfc.c b/drivers/mtd/nand/raw/vf610_nfc.c
index acc9ff282083..547eb1513893 100644
--- a/drivers/mtd/nand/raw/vf610_nfc.c
+++ b/drivers/mtd/nand/raw/vf610_nfc.c
@@ -154,6 +154,7 @@ struct vf610_nfc {
struct device *dev;
void __iomem *regs;
struct completion cmd_done;
+ int irq;
/* Status and ID are in alternate locations. */
enum vf610_nfc_variant variant;
struct clk *clk;
@@ -291,6 +292,9 @@ static void vf610_nfc_done(struct vf610_nfc *nfc)
{
unsigned long timeout = msecs_to_jiffies(100);
+ vf610_nfc_clear_status(nfc);
+ reinit_completion(&nfc->cmd_done);
+
/*
* Barrier is needed after this write. This write need
* to be done before reading the next register the first
@@ -301,8 +305,11 @@ static void vf610_nfc_done(struct vf610_nfc *nfc)
vf610_nfc_set(nfc, NFC_IRQ_STATUS, IDLE_EN_BIT);
vf610_nfc_set(nfc, NFC_FLASH_CMD2, START_BIT);
- if (!wait_for_completion_timeout(&nfc->cmd_done, timeout))
+ if (!wait_for_completion_timeout(&nfc->cmd_done, timeout)) {
dev_warn(nfc->dev, "Timeout while waiting for BUSY.\n");
+ vf610_nfc_clear(nfc, NFC_IRQ_STATUS, IDLE_EN_BIT);
+ synchronize_irq(nfc->irq);
+ }
vf610_nfc_clear_status(nfc);
}
@@ -885,6 +892,7 @@ static int vf610_nfc_probe(struct platform_device *pdev)
irq = platform_get_irq(pdev, 0);
if (irq < 0)
return irq;
+ nfc->irq = irq;
nfc->regs = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(nfc->regs))
--
2.56.0