[PATCH] mtd: nand: ecc: release OF node reference when platform device is not ready
From: Ziheng Wei
Date: Fri Dec 04 2026 - 04:11:55 EST
In nand_ecc_get_on_host_hw_engine(), of_parse_phandle() acquires a
reference on the nand-ecc-engine device_node. If of_find_device_by_node()
returns NULL, the function returns ERR_PTR(-EPROBE_DEFER) without calling
of_node_put(np), leaking a device_node reference on every deferred probe.
Call of_node_put(np) right after of_find_device_by_node(np).
Found by LLM-assisted static analysis. Compile-tested on x86_64.
Fixes: 96489c1c0b53 ("mtd: nand: ecc: Add infrastructure to support hardware engines")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Ziheng Wei <zihengw03@xxxxxxx>
---
drivers/mtd/nand/ecc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/mtd/nand/ecc.c b/drivers/mtd/nand/ecc.c
index 1d809cbd4..11a3c98aa 100644
--- a/drivers/mtd/nand/ecc.c
+++ b/drivers/mtd/nand/ecc.c
@@ -682,12 +682,12 @@ struct nand_ecc_engine *nand_ecc_get_on_host_hw_engine(struct nand_device *nand)
np = of_parse_phandle(dev->of_node, "nand-ecc-engine", 0);
if (np) {
pdev = of_find_device_by_node(np);
+ of_node_put(np);
if (!pdev)
return ERR_PTR(-EPROBE_DEFER);
engine = nand_ecc_match_on_host_hw_engine(&pdev->dev);
platform_device_put(pdev);
- of_node_put(np);
if (!engine)
return ERR_PTR(-EPROBE_DEFER);
base-commit: 97d73c8251226cf27cc6656b4c542869bb8c69fa
--
2.43.0