[PATCH] mtd: rawnand: atmel: release the NFC IRQ before controller cleanup

Miquel Raynal miquel.raynal at bootlin.com
Fri Nov 20 06:42:16 PST 2026


On 08/11/2026 at 14:07:31 -07, James Hilliard <james.hilliard1 at gmail.com> wrote:

> The NFC interrupt is shared and devm-managed. Controller removal disables
> the clock used by the legacy binding before devres releases the handler.
> An interrupt from another device on the shared line can therefore make
> atmel_nfc_interrupt() read the NFC status with its clock disabled.
>
> Release and drain the handler before freeing the controller resources.
> Track successful IRQ registration because probe also uses this cleanup
> path when requesting the IRQ itself fails.
>
> Fixes: f88fc122cc34 ("mtd: nand: Cleanup/rework the atmel_nand driver")
> Cc: stable at vger.kernel.org
> Signed-off-by: James Hilliard <james.hilliard1 at gmail.com>
> ---
>  drivers/mtd/nand/raw/atmel/nand-controller.c | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/drivers/mtd/nand/raw/atmel/nand-controller.c b/drivers/mtd/nand/raw/atmel/nand-controller.c
> index 0bdbcbb50d94..9a724de67624 100644
> --- a/drivers/mtd/nand/raw/atmel/nand-controller.c
> +++ b/drivers/mtd/nand/raw/atmel/nand-controller.c
> @@ -263,6 +263,7 @@ struct atmel_hsmc_nand_controller {
>  	struct completion complete;
>  	u32 cfg;
>  	int irq;
> +	bool irq_requested;
>  
>  	/* Only used when instantiating from legacy DT bindings. */
>  	struct clk *clk;
> @@ -2334,6 +2335,9 @@ atmel_hsmc_nand_controller_remove(struct atmel_nand_controller *nc)
>  	regmap_write(hsmc_nc->base.smc, ATMEL_HSMC_NFC_CTRL,
>  		     ATMEL_HSMC_NFC_CTRL_DIS);
>  
> +	if (hsmc_nc->irq_requested)
> +		devm_free_irq(nc->dev, hsmc_nc->irq, hsmc_nc);
> +

That's a terrible approach, completely defeating the main purpose of
devres.

Your problem is a devres ordering. The fix should be by teaching devres
the right order instead of open coding the fix. So you need a
***_clk_cleanup() helper which does:

	clk_disable_unprepare(nc->clk);
	clk_put(nc->clk);

and you want to register it before the IRQ request so it is triggered
after:

        devm_add_action_or_reset(dev, ***_clk_cleanup, ...);

Thanks,
Miquèl



More information about the linux-mtd mailing list