Skip to content

Commit

Permalink
Set last_comp_version correctly in new dtb and fix potential version …
Browse files Browse the repository at this point in the history
…issues in fdt_open_into

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

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

Signed-off-by: Justin Covell <jujugoboom@gmail.com>

Message-Id: <20201229041749.2187-1-jujugoboom@gmail.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
  • Loading branch information
jujugoboom authored and dgibson committed Jan 4, 2021
1 parent f7e5737 commit 3b01518
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion libfdt/fdt_rw.c
Expand Up @@ -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) ||
Expand Down
2 changes: 1 addition & 1 deletion libfdt/fdt_sw.c
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions libfdt/libfdt.h
Expand Up @@ -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 */
Expand Down

0 comments on commit 3b01518

Please sign in to comment.