Skip to contentSkip to conversation

optee: fix copy of optee reserved-memory node

PATCH New Patrick Delaunay 2 participants 3 messages Jun 5, 2020 – Jun 15, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 optee: fix copy of optee reserved-memory node

From: Etienne Carriere <[email protected]>

Fix the loop that parses FDT for a reserved memory node named "optee".

Before this change, if at least one subnode was found in the reserved-memory node, the function endlessly looped since instruction continue returned back in the loop without updating variable subnode. This change fixes the issue by using a for loop.

Fixes 6ccb05eae01b ("image: fdt: copy possible optee nodes to a loaded devicetree")

---

 lib/optee/optee.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
lib/optee/optee.c +3 -4
index e59b5766e7..457d4cca8a 100644
@@ -156,8 +156,9 @@ int optee_copy_fdt_nodes(const void *old_blob, void *new_blob)
 	/* optee inserts its memory regions as reserved-memory nodes */
 	nodeoffset = fdt_subnode_offset(old_blob, 0, "reserved-memory");
 	if (nodeoffset >= 0) {
-		subnode = fdt_first_subnode(old_blob, nodeoffset);
-		while (subnode >= 0) {
+		for (subnode = fdt_first_subnode(old_blob, nodeoffset);
+		     subnode >= 0;
+		     subnode = fdt_next_subnode(old_blob, subnode)) {
 			const char *name = fdt_get_name(old_blob,
 							subnode, NULL);
 			if (!name)
@@ -197,8 +198,6 @@ int optee_copy_fdt_nodes(const void *old_blob, void *new_blob)
 				if (ret < 0)
 					return ret;
 			}
-
-			subnode = fdt_next_subnode(old_blob, subnode);
 		}
 	}
 
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/1 optee: fix copy of optee reserved-memory node

Hi Tom,

Quoted 49 lines

From: Patrick DELAUNAY <[email protected]>
Sent: vendredi 5 juin 2020 09:22

From: Etienne Carriere <[email protected]>

Fix the loop that parses FDT for a reserved memory node named "optee".

Before this change, if at least one subnode was found in the reserved-memory node, the function endlessly looped since instruction continue returned back in the loop without updating variable subnode.
This change fixes the issue by using a for loop.

Fixes 6ccb05eae01b ("image: fdt: copy possible optee nodes to a loaded

devicetree")

---

 lib/optee/optee.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
lib/optee/optee.c index e59b5766e7..457d4cca8a renamed from lib/optee/optee.c +0 -0

100644

lib/optee/optee.c +3 -2
@@ -156,8 +156,9 @@ int optee_copy_fdt_nodes(const void *old_blob, void
 *new_blob)
 	/* optee inserts its memory regions as reserved-memory nodes */
 	nodeoffset = fdt_subnode_offset(old_blob, 0, "reserved-memory");
 	if (nodeoffset >= 0) {
-		subnode = fdt_first_subnode(old_blob, nodeoffset);
-		while (subnode >= 0) {
+		for (subnode = fdt_first_subnode(old_blob, nodeoffset);
+		     subnode >= 0;
+		     subnode = fdt_next_subnode(old_blob, subnode)) {
 			const char *name = fdt_get_name(old_blob,
 							subnode, NULL);
lib/optee/optee.c +0 -3
 			if (!name)
@@ -197,8 +198,6 @@ int optee_copy_fdt_nodes(const void *old_blob, void
 *new_blob)
 				if (ret < 0)
 					return ret;
 			}
-
-			subnode = fdt_next_subnode(old_blob, subnode);
 		}
 	}
 
--
Quoted 1 line

2.17.1

Do you think it is possible to include this fix in v2020.07 ? Or do you expect some review ?

This issue blocks the STM32MP1 boot with OP-TEE...
as subnode is not update if the first reserved node is not "optee" one, with:

	if (strncmp(name, "optee", 5))
		continue;

for example DT =

reserved-memory {
	gpu_reserved: gpu at da000000 {
		reg = <0xda000000 0x4000000>;
		no-map;
	};

	optee at de000000 {
		reg = <0xde000000 0x02000000>;
		no-map;
	};
};

See also http://patchwork.ozlabs.org/project/uboot/list/?series=181471

Regards

Patrick

#2 lore raw

PATCH 1/1 optee: fix copy of optee reserved-memory node

In reply to Patrick Delaunay
Quoted 4 lines · Patrick Delaunay

From: Etienne Carriere <[email protected]>

Fix the loop that parses FDT for a reserved memory node named "optee".

Quoted 8 lines

Before this change, if at least one subnode was found in the reserved-memory node, the function endlessly looped since instruction continue returned back in the loop without updating variable subnode. This change fixes the issue by using a for loop.

Fixes 6ccb05eae01b ("image: fdt: copy possible optee nodes to a loaded devicetree")

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200615/76e93885/attachment.sig>