Skip to contentSkip to conversation

fdt_shrink_to_minimum: do not mark fdt space reserved unconditionally

PATCH New Simon Goldschmidt 3 participants 3 messages May 3, 2019 – May 10, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fdt_shrink_to_minimum: do not mark fdt space reserved unconditionally

This function merely relocates the fdt blob, so don't let it alter it by adding reservations that didn't exist before.

Instead, if the memory used for the fdt blob has been reserved before calling this function, ensure the relocated memory is marked as reserved instead.

---

 common/fdt_support.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
common/fdt_support.c +8 -4
index ab08a0114f..4e7cf6ebe9 100644
@@ -597,6 +597,7 @@ int fdt_shrink_to_minimum(void *blob, uint extrasize)
 	uint64_t addr, size;
 	int total, ret;
 	uint actualsize;
+	int fdt_memrsv = 0;
 
 	if (!blob)
 		return 0;
@@ -606,6 +607,7 @@ int fdt_shrink_to_minimum(void *blob, uint extrasize)
 		fdt_get_mem_rsv(blob, i, &addr, &size);
 		if (addr == (uintptr_t)blob) {
 			fdt_del_mem_rsv(blob, i);
+			fdt_memrsv = 1;
 			break;
 		}
 	}
@@ -627,10 +629,12 @@ int fdt_shrink_to_minimum(void *blob, uint extrasize)
 	/* Change the fdt header to reflect the correct size */
 	fdt_set_totalsize(blob, actualsize);
 
-	/* Add the new reservation */
-	ret = fdt_add_mem_rsv(blob, map_to_sysmem(blob), actualsize);
-	if (ret < 0)
-		return ret;
+	if (fdt_memrsv) {
+		/* Add the new reservation */
+		ret = fdt_add_mem_rsv(blob, map_to_sysmem(blob), actualsize);
+		if (ret < 0)
+			return ret;
+	}
 
 	return actualsize;
 }
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/1 fdt_shrink_to_minimum: do not mark fdt space reserved unconditionally

Quoted 10 lines · Simon Goldschmidt

This function merely relocates the fdt blob, so don't let it alter it by adding reservations that didn't exist before.

Instead, if the memory used for the fdt blob has been reserved before calling this function, ensure the relocated memory is marked as reserved instead.

Thanks and regards,
Lokesh

Quoted 43 lines

---

 common/fdt_support.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
common/fdt_support.c +8 -4
index ab08a0114f..4e7cf6ebe9 100644
@@ -597,6 +597,7 @@ int fdt_shrink_to_minimum(void *blob, uint extrasize)
 	uint64_t addr, size;
 	int total, ret;
 	uint actualsize;
+	int fdt_memrsv = 0;
 
 	if (!blob)
 		return 0;
@@ -606,6 +607,7 @@ int fdt_shrink_to_minimum(void *blob, uint extrasize)
 		fdt_get_mem_rsv(blob, i, &addr, &size);
 		if (addr == (uintptr_t)blob) {
 			fdt_del_mem_rsv(blob, i);
+			fdt_memrsv = 1;
 			break;
 		}
 	}
@@ -627,10 +629,12 @@ int fdt_shrink_to_minimum(void *blob, uint extrasize)
 	/* Change the fdt header to reflect the correct size */
 	fdt_set_totalsize(blob, actualsize);
 
-	/* Add the new reservation */
-	ret = fdt_add_mem_rsv(blob, map_to_sysmem(blob), actualsize);
-	if (ret < 0)
-		return ret;
+	if (fdt_memrsv) {
+		/* Add the new reservation */
+		ret = fdt_add_mem_rsv(blob, map_to_sysmem(blob), actualsize);
+		if (ret < 0)
+			return ret;
+	}
 
 	return actualsize;
 }
#2 lore raw

PATCH 1/1 fdt_shrink_to_minimum: do not mark fdt space reserved unconditionally

In reply to Simon Goldschmidt
Quoted 11 lines · Simon Goldschmidt

This function merely relocates the fdt blob, so don't let it alter it by adding reservations that didn't exist before.

Instead, if the memory used for the fdt blob has been reserved before calling this function, ensure the relocated memory is marked as reserved instead.

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: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190510/2f695d10/attachment.sig>