[PATCH] of: Fix phandle_node reference leak in of_map_id()

Wentao Liang posted 1 patch 1 week ago
drivers/of/base.c | 2 ++
1 file changed, 2 insertions(+)
[PATCH] of: Fix phandle_node reference leak in of_map_id()
Posted by Wentao Liang 1 week ago
of_find_node_by_phandle() returns a node with an elevated reference
count. When the caller passes target == NULL it only wants the
translated ID, so that reference is never handed over and must be
dropped before returning success.

Fixes: 987068fcbdb7 ("of/irq: Break out msi-map lookup (again)")
Cc: stable@vger.kernel.org
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
 drivers/of/base.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index a650c91897cc..0f548d103037 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -2201,6 +2201,8 @@ int of_map_id(const struct device_node *np, u32 id,
 
 			if (*target != phandle_node)
 				continue;
+		} else {
+			of_node_put(phandle_node);
 		}
 
 		if (id_out)
-- 
2.34.1