mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Cc: Ahmad Fatoum <afa@pengutronix.de>
Subject: [PATCH] of: Fix of_get_stdoutpath() when property does not contain a colon
Date: Thu, 23 Feb 2023 11:31:01 +0100	[thread overview]
Message-ID: <20230223103101.1904100-1-s.hauer@pengutronix.de> (raw)

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@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




                 reply	other threads:[~2023-02-23 10:32 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230223103101.1904100-1-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=afa@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox