bus: ti-sysc: Fix /chosen node reference leak

sysc_init_stdout_path() gets the /chosen node with
of_find_node_by_path() to read stdout-path. The function then overwrites
the local node pointer with the stdout-path lookup result, or exits on
error, without dropping the /chosen reference.

Keep the /chosen node in a separate variable and put it after the
stdout-path value has been used for the lookup. The successful stdout
node lookup remains referenced by the cached stdout_path pointer.

Fixes: 3bb37c8e6e ("bus: ti-sysc: Handle stdout-path for debug console")
Signed-off-by: Yuho Choi <dbgh9129@gmail.com>
Reviewed-by: Andreas Kemnade <andreas@kemnade.info>
Link: https://patch.msgid.link/20260615200540.770205-1-dbgh9129@gmail.com
Signed-off-by: Kevin Hilman (TI) <khilman@baylibre.com>
This commit is contained in:
Yuho Choi
2026-07-06 11:42:48 -07:00
committed by Kevin Hilman (TI)
parent dc59e4fea9
commit 6342de0aed
+8 -4
View File
@@ -682,6 +682,7 @@ static struct device_node *stdout_path;
static void sysc_init_stdout_path(struct sysc *ddata)
{
struct device_node *chosen;
struct device_node *np = NULL;
const char *uart;
@@ -691,15 +692,18 @@ static void sysc_init_stdout_path(struct sysc *ddata)
if (stdout_path)
return;
np = of_find_node_by_path("/chosen");
if (!np)
chosen = of_find_node_by_path("/chosen");
if (!chosen)
goto err;
uart = of_get_property(np, "stdout-path", NULL);
if (!uart)
uart = of_get_property(chosen, "stdout-path", NULL);
if (!uart) {
of_node_put(chosen);
goto err;
}
np = of_find_node_by_path(uart);
of_node_put(chosen);
if (!np)
goto err;