Skip to contentSkip to conversation

Set last_comp_version correctly in new dtb and fix potential version issues in fdt_open_into

PATCH Applied Justin Covell 2 participants 2 messages Dec 29, 2020 – Jan 4, 2021 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 Set last_comp_version correctly in new dtb and fix potential version issues in fdt_open_into

Changes in v3:
- Remove noop version sets
- Set version correctly on loaded fdt in fdt_open_into

Fixes f1879e1a50eb ("Add limited read-only support for older (V2 and V3) device tree to libfdt.")
---
 libfdt/fdt_rw.c | 4 +++-
 libfdt/fdt_sw.c | 2 +-
 libfdt/libfdt.h | 1 +
 3 files changed, 5 insertions(+), 2 deletions(-)
libfdt/fdt_rw.c +3 -1
index 68887b9..f13458d 100644
@@ -428,12 +428,14 @@ int fdt_open_into(const void *fdt, void *buf, int bufsize)
 
 	if (can_assume(LATEST) || fdt_version(fdt) >= 17) {
 		struct_size = fdt_size_dt_struct(fdt);
-	} else {
+	} else if (fdt_version(fdt) == 16) {
 		struct_size = 0;
 		while (fdt_next_tag(fdt, struct_size, &struct_size) != FDT_END)
 			;
 		if (struct_size < 0)
 			return struct_size;
+	} else {
+		return -FDT_ERR_BADVERSION;
 	}
 
 	if (can_assume(LIBFDT_ORDER) ||
libfdt/fdt_sw.c +1 -1
index 68b543c..4c569ee 100644
@@ -377,7 +377,7 @@ int fdt_finish(void *fdt)
 	fdt_set_totalsize(fdt, newstroffset + fdt_size_dt_strings(fdt));
 
 	/* And fix up fields that were keeping intermediate state. */
-	fdt_set_last_comp_version(fdt, FDT_FIRST_SUPPORTED_VERSION);
+	fdt_set_last_comp_version(fdt, FDT_LAST_COMPATIBLE_VERSION);
 	fdt_set_magic(fdt, FDT_MAGIC);
 
 	return 0;
libfdt/libfdt.h +1 -0
index 2bc16a8..73467f7 100644
@@ -14,6 +14,7 @@ extern "C" {
 #endif
 
 #define FDT_FIRST_SUPPORTED_VERSION	0x02
+#define FDT_LAST_COMPATIBLE_VERSION 0x10
 #define FDT_LAST_SUPPORTED_VERSION	0x11
 
 /* Error codes: informative error codes */
Signature · 1 line
2.25.1

A message that is not in the archive (sent off-list or not yet received): 20201229041749.2187-1-jujugoboom-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

Applied
#2 lore raw
Quoted 7 lines · Justin Covell

Changes in v3:
- Remove noop version sets
- Set version correctly on loaded fdt in fdt_open_into

Fixes f1879e1a50eb ("Add limited read-only support for older (V2 and V3) device tree to libfdt.")

Applied, thanks.

Quoted 52 lines
---
 libfdt/fdt_rw.c | 4 +++-
 libfdt/fdt_sw.c | 2 +-
 libfdt/libfdt.h | 1 +
 3 files changed, 5 insertions(+), 2 deletions(-)
libfdt/fdt_rw.c +3 -1
index 68887b9..f13458d 100644
@@ -428,12 +428,14 @@ int fdt_open_into(const void *fdt, void *buf, int bufsize)
 
 	if (can_assume(LATEST) || fdt_version(fdt) >= 17) {
 		struct_size = fdt_size_dt_struct(fdt);
-	} else {
+	} else if (fdt_version(fdt) == 16) {
 		struct_size = 0;
 		while (fdt_next_tag(fdt, struct_size, &struct_size) != FDT_END)
 			;
 		if (struct_size < 0)
 			return struct_size;
+	} else {
+		return -FDT_ERR_BADVERSION;
 	}
 
 	if (can_assume(LIBFDT_ORDER) ||
libfdt/fdt_sw.c +1 -1
index 68b543c..4c569ee 100644
@@ -377,7 +377,7 @@ int fdt_finish(void *fdt)
 	fdt_set_totalsize(fdt, newstroffset + fdt_size_dt_strings(fdt));
 
 	/* And fix up fields that were keeping intermediate state. */
-	fdt_set_last_comp_version(fdt, FDT_FIRST_SUPPORTED_VERSION);
+	fdt_set_last_comp_version(fdt, FDT_LAST_COMPATIBLE_VERSION);
 	fdt_set_magic(fdt, FDT_MAGIC);
 
 	return 0;
libfdt/libfdt.h +1 -0
index 2bc16a8..73467f7 100644
@@ -14,6 +14,7 @@ extern "C" {
 #endif
 
 #define FDT_FIRST_SUPPORTED_VERSION	0x02
+#define FDT_LAST_COMPATIBLE_VERSION 0x10
 #define FDT_LAST_SUPPORTED_VERSION	0x11
 
 /* Error codes: informative error codes */
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson