* [PATCH] mtd: rawnand: atmel: Fix MCK clock leak in atmel_nand_controller_init()
@ 2026-09-17 10:29 Wentao Liang
2026-09-25 13:35 ` Miquel Raynal
0 siblings, 1 reply; 2+ messages in thread
From: Wentao Liang @ 2026-09-17 10:29 UTC (permalink / raw)
To: alexandre.belloni
Cc: bbrezillon, claudiu.beznea, linux-arm-kernel, linux-kernel,
linux-mtd, miquel.raynal, nicolas.ferre, richard, vigneshr,
Wentao Liang, stable
atmel_nand_controller_init() takes a reference to the MCK clock with
of_clk_get() and keeps it in nc->mck for the lifetime of the
controller. If the "atmel,smc" phandle is missing or the SMC regmap
cannot be obtained afterwards, the error path jumps to out_release_dma
which only releases the DMA channel, so the clock reference is leaked.
The callers return the error directly and never run
atmel_nand_controller_cleanup(), where the clock is normally put.
Release the reference on those error paths. The path on which
of_clk_get() itself fails keeps jumping to out_release_dma, as nc->mck
only holds an error pointer there.
Fixes: f9ce2eddf176 ("mtd: nand: atmel: Add ->setup_data_interface() hooks")
Cc: stable@vger.kernel.org
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
drivers/mtd/nand/raw/atmel/nand-controller.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/mtd/nand/raw/atmel/nand-controller.c b/drivers/mtd/nand/raw/atmel/nand-controller.c
index 87d9227f6ecc..d61e84b8bc60 100644
--- a/drivers/mtd/nand/raw/atmel/nand-controller.c
+++ b/drivers/mtd/nand/raw/atmel/nand-controller.c
@@ -2086,7 +2086,7 @@ static int atmel_nand_controller_init(struct atmel_nand_controller *nc,
if (!np) {
dev_err(dev, "Missing or invalid atmel,smc property\n");
ret = -EINVAL;
- goto out_release_dma;
+ goto out_put_mck;
}
nc->smc = syscon_node_to_regmap(np);
@@ -2094,11 +2094,13 @@ static int atmel_nand_controller_init(struct atmel_nand_controller *nc,
if (IS_ERR(nc->smc)) {
ret = PTR_ERR(nc->smc);
dev_err(dev, "Could not get SMC regmap (err = %d)\n", ret);
- goto out_release_dma;
+ goto out_put_mck;
}
return 0;
+out_put_mck:
+ clk_put(nc->mck);
out_release_dma:
if (nc->dmac)
dma_release_channel(nc->dmac);
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] mtd: rawnand: atmel: Fix MCK clock leak in atmel_nand_controller_init()
2026-09-17 10:29 [PATCH] mtd: rawnand: atmel: Fix MCK clock leak in atmel_nand_controller_init() Wentao Liang
@ 2026-09-25 13:35 ` Miquel Raynal
0 siblings, 0 replies; 2+ messages in thread
From: Miquel Raynal @ 2026-09-25 13:35 UTC (permalink / raw)
To: alexandre.belloni, Wentao Liang
Cc: bbrezillon, claudiu.beznea, linux-arm-kernel, linux-kernel,
linux-mtd, nicolas.ferre, richard, vigneshr, stable
On Thu, 17 Sep 2026 10:29:24 +0000, Wentao Liang wrote:
> atmel_nand_controller_init() takes a reference to the MCK clock with
> of_clk_get() and keeps it in nc->mck for the lifetime of the
> controller. If the "atmel,smc" phandle is missing or the SMC regmap
> cannot be obtained afterwards, the error path jumps to out_release_dma
> which only releases the DMA channel, so the clock reference is leaked.
> The callers return the error directly and never run
> atmel_nand_controller_cleanup(), where the clock is normally put.
>
> [...]
Applied to nand/next, thanks!
[1/1] mtd: rawnand: atmel: Fix MCK clock leak in atmel_nand_controller_init()
commit: 94edcda45d888c3bb1310de11e10e4537c166f00
Patche(s) should be available on mtd/linux.git and will be
part of the next PR (provided that no robot complains by then).
Kind regards,
Miquèl
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-09-25 13:36 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-17 10:29 [PATCH] mtd: rawnand: atmel: Fix MCK clock leak in atmel_nand_controller_init() Wentao Liang
2026-09-25 13:35 ` Miquel Raynal
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).