[PATCH] of: Fix of_get_stdoutpath() when property does not contain a colon

Sascha Hauer s.hauer at pengutronix.de
Thu Feb 23 02:31:01 PST 2023


With 90f70dbe29 'buf' only gets initialized when the stdout-path
property contains a colon. It changes

	p = strchrnul(value, ':');
	buf = xstrndup(value, p - value);

to
	p = strchrnul(value, ':');
	if (*p)
		buf = xstrndup(value, p - value);

With the latter we end up calling of_find_node_by_path_or_alias() with
a NULL pointer, so no node can be found.

Fix this by restoring the original behaviour.

Fixes: 90f70dbe29 ("of: split part of of_get_stdoutpath into of_find_node_by_chosen")
Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/of/base.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 34854d9b0d..fb23594c7a 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -2680,7 +2680,7 @@ struct device_node *of_find_node_by_chosen(const char *propname,
 					   const char **options)
 {
 	const char *value, *p;
-	char *buf = NULL;
+	char *buf;
 	struct device_node *dn;
 
 	value = of_get_property(of_chosen, propname, NULL);
@@ -2688,8 +2688,7 @@ struct device_node *of_find_node_by_chosen(const char *propname,
 		return NULL;
 
 	p = strchrnul(value, ':');
-	if (*p)
-		buf = xstrndup(value, p - value);
+	buf = xstrndup(value, p - value);
 
 	dn = of_find_node_by_path_or_alias(NULL, buf);
 
-- 
2.30.2




More information about the barebox mailing list