Skip to contentSkip to conversation

of: make sure of_alias is initialized before accessing it

PATCH In review Laurentiu Tudor 2 participants 3 messages Aug 27, 2014 – Sep 8, 2014 Device tree

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 of: make sure of_alias is initialized before accessing it

Simply swap of_alias and of_chosen initialization so that of_alias ends up read first. This must be done because it is accessed couple of lines below when trying to initialize the of_stdout using the alias based legacy method.

[Fixes a752ee5 - tty: Update hypervisor tty drivers to use core stdout parsing code]

---
 drivers/of/base.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/of/base.c +4 -4
index d8574ad..52f8506 100644
@@ -1847,6 +1847,10 @@ void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align))
 {
 	struct property *pp;
 
+	of_aliases = of_find_node_by_path("/aliases");
+	if (!of_aliases)
+		return;
+
 	of_chosen = of_find_node_by_path("/chosen");
 	if (of_chosen == NULL)
 		of_chosen = of_find_node_by_path("/chosen@0");
@@ -1862,10 +1866,6 @@ void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align))
 			of_stdout = of_find_node_by_path(name);
 	}
 
-	of_aliases = of_find_node_by_path("/aliases");
-	if (!of_aliases)
-		return;
-
 	for_each_property_of_node(of_aliases, pp) {
 		const char *start = pp->name;
 		const char *end = start + strlen(start);
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 31 lines · Laurentiu Tudor

Simply swap of_alias and of_chosen initialization so that of_alias ends up read first. This must be done because it is accessed couple of lines below when trying to initialize the of_stdout using the alias based legacy method.

[Fixes a752ee5 - tty: Update hypervisor tty drivers to use core stdout parsing code]

---
 drivers/of/base.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/of/base.c +4 -0
index d8574ad..52f8506 100644
@@ -1847,6 +1847,10 @@ void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align))
 {
 	struct property *pp;
 
+	of_aliases = of_find_node_by_path("/aliases");
+	if (!of_aliases)
+		return;
+
 	of_chosen = of_find_node_by_path("/chosen");
 	if (of_chosen == NULL)
 		of_chosen = of_find_node_by_path("/chosen@0");

drivers/of/base.c void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align)) · line 1868

Quoted 7 lines
drivers/of/base.c +0 -4
@@ -1862,10 +1866,6 @@ void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align))
 			of_stdout = of_find_node_by_path(name);
 	}
 
-	of_aliases = of_find_node_by_path("/aliases");
-	if (!of_aliases)
-		return;
-

Close, but not quite. The 'if (!of_aliases)' test should not be moved. Only the search for of_find_node_by_path(). I've fixed it up and applied.

g.

Quoted 5 lines
drivers/of/base.c +0 -0
 	for_each_property_of_node(of_aliases, pp) {
 		const char *start = pp->name;
 		const char *end = start + strlen(start);
Signature · 1 line
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw
Quoted 35 lines · Grant Likely
Quoted 34 lines · Laurentiu Tudor

Simply swap of_alias and of_chosen initialization so that of_alias ends up read first. This must be done because it is accessed couple of lines below when trying to initialize the of_stdout using the alias based legacy method.

[Fixes a752ee5 - tty: Update hypervisor tty drivers to use core stdout parsing code]

---
 drivers/of/base.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/of/base.c +4 -0
index d8574ad..52f8506 100644
@@ -1847,6 +1847,10 @@ void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align))
 {
 	struct property *pp;
 
+	of_aliases = of_find_node_by_path("/aliases");
+	if (!of_aliases)
+		return;
+
 	of_chosen = of_find_node_by_path("/chosen");
 	if (of_chosen == NULL)
 		of_chosen = of_find_node_by_path("/chosen@0");
@@ -1862,10 +1866,6 @@ void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align))
 			of_stdout = of_find_node_by_path(name);
 	}
 
Quoted 7 lines

drivers/of/base.c void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align)) · line 1868

Quoted 4 lines
drivers/of/base.c +0 -4
-	of_aliases = of_find_node_by_path("/aliases");
-	if (!of_aliases)
-		return;
-

Close, but not quite. The 'if (!of_aliases)' test should not be moved. Only the search for of_find_node_by_path().

Eek, completely missed this. Sorry.

Quoted 1 line

I've fixed it up and applied.

Thanks!

---
Best Regards, Laurentiu
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html