Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mtd: rawnand: atmel: release the NFC IRQ before controller cleanup
@ 2026-11-08 21:07 James Hilliard
  2026-11-20 14:42 ` Miquel Raynal
  0 siblings, 1 reply; 2+ messages in thread
From: James Hilliard @ 2026-11-08 21:07 UTC (permalink / raw)
  To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Nicolas Ferre, Alexandre Belloni, Claudiu Beznea, Boris Brezillon
  Cc: linux-mtd, linux-kernel, linux-arm-kernel, stable, James Hilliard

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@vger.kernel.org
Signed-off-by: James Hilliard <james.hilliard1@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);
+
 	if (hsmc_nc->sram.pool)
 		gen_pool_free(hsmc_nc->sram.pool,
 			      (unsigned long)hsmc_nc->sram.virt,
@@ -2383,6 +2387,8 @@ static int atmel_hsmc_nand_controller_probe(struct platform_device *pdev,
 		goto err;
 	}
 
+	nc->irq_requested = true;
+
 	/* Initial NFC configuration. */
 	regmap_write(nc->base.smc, ATMEL_HSMC_NFC_CFG,
 		     ATMEL_HSMC_NFC_CFG_DTO_MAX);

---
base-commit: 30daaf3e7897b4a8d9b72e5b0c86dd6e2a4d7d85
change-id: 20261107-submit-atmel-nand-irq-teardown-v1-f902307c18db

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



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] mtd: rawnand: atmel: release the NFC IRQ before controller cleanup
  2026-11-08 21:07 [PATCH] mtd: rawnand: atmel: release the NFC IRQ before controller cleanup James Hilliard
@ 2026-11-20 14:42 ` Miquel Raynal
  0 siblings, 0 replies; 2+ messages in thread
From: Miquel Raynal @ 2026-11-20 14:42 UTC (permalink / raw)
  To: James Hilliard
  Cc: Richard Weinberger, Vignesh Raghavendra, Nicolas Ferre,
	Alexandre Belloni, Claudiu Beznea, Boris Brezillon, linux-mtd,
	linux-kernel, linux-arm-kernel, stable

On 08/11/2026 at 14:07:31 -07, James Hilliard <james.hilliard1@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@vger.kernel.org
> Signed-off-by: James Hilliard <james.hilliard1@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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-20 14:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-08 21:07 [PATCH] mtd: rawnand: atmel: release the NFC IRQ before controller cleanup James Hilliard
2026-11-20 14:42 ` Miquel Raynal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox