[PATCH v7 04/16] mtd: rawnand: sunxi: drain interrupts before reusing the completion

Sebastian Andrzej Siewior bigeasy at linutronix.de
Thu Oct 15 00:19:43 PDT 2026


On 2026-10-14 19:33:51 [-0600], James Hilliard wrote:
> --- a/drivers/mtd/nand/raw/sunxi_nand.c
> +++ b/drivers/mtd/nand/raw/sunxi_nand.c
> @@ -454,16 +457,19 @@ static int sunxi_nfc_wait_events(struct sunxi_nfc *nfc, u32 events,
>  		timeout_ms = NFC_DEFAULT_TIMEOUT_MS;
>  
>  	if (!use_polling) {
> -		init_completion(&nfc->complete);
> +		reinit_completion(&nfc->complete);
>  
>  		writel(events, nfc->regs + NFC_REG_INT);
>  
>  		ret = wait_for_completion_timeout(&nfc->complete,
>  						msecs_to_jiffies(timeout_ms));
> -		if (!ret)
> +		if (!ret) {
> +			/* Drain the handler before it can restore an old IRQ mask. */
> +			disable_irq(nfc->irq);
>  			ret = -ETIMEDOUT;
> -		else
> +		} else {
>  			ret = 0;
> +		}
>  
>  		writel(0, nfc->regs + NFC_REG_INT);
>  	} else {
> @@ -476,6 +482,12 @@ static int sunxi_nfc_wait_events(struct sunxi_nfc *nfc, u32 events,
>  
>  	writel(events & NFC_INT_MASK, nfc->regs + NFC_REG_ST);
>  
> +	if (!use_polling && ret) {
> +		/* Flush the mask and acknowledgment before re-enabling the IRQ. */
> +		readl(nfc->regs + NFC_REG_INT);
> +		enable_irq(nfc->irq);

Shouldn't you re-read NFC_REG_ST, checking if the event became true even
in the case of a timeout?
Say the interrupt wake the thread but the thread never had a chance
to run. The timer (on another CPU) had a chance to run and did wake this
thread. Checking the event in the timeout case would help to prevent
that.

> +	}
> +
>  	if (ret)
>  		dev_err(nfc->dev, "wait interrupt timedout\n");
>  

Sebastian



More information about the linux-mtd mailing list