mirror of
https://github.com/dgibson/dtc.git
synced 2025-10-13 16:27:39 -04:00
libfdt: Remove un-const-safe fdt_set_header macro
The fdt_set_header() macro casts an arbitrary pointer into (struct fdt_header *) to set fdt header fields. While we need to change the type, so that we can use this macro on the usual (void *) used to represent a device tree blob, the current macro also casts away any const on the input pointer, which loses an important check. This patch replaces the fdt_set_header() macro with a set of inline functions, one for each header field which do a similar thing, but which won't silently remove const from a given pointer. This approach is also more in keeping with the individual accessor macros we use for reading fdt header fields. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
parent
57f99b7b3f
commit
9b91134ba3
3 changed files with 38 additions and 23 deletions
|
@ -73,7 +73,7 @@ static void *grab_space(void *fdt, int len)
|
|||
if ((offset + len < offset) || (offset + len > spaceleft))
|
||||
return NULL;
|
||||
|
||||
fdt_set_header(fdt, size_dt_struct, offset + len);
|
||||
fdt_set_size_dt_struct(fdt, offset + len);
|
||||
return fdt_offset_ptr_w(fdt, offset, len);
|
||||
}
|
||||
|
||||
|
@ -86,15 +86,15 @@ int fdt_create(void *buf, int bufsize)
|
|||
|
||||
memset(buf, 0, bufsize);
|
||||
|
||||
fdt_set_header(fdt, magic, SW_MAGIC);
|
||||
fdt_set_header(fdt, version, FDT_LAST_SUPPORTED_VERSION);
|
||||
fdt_set_header(fdt, last_comp_version, FDT_FIRST_SUPPORTED_VERSION);
|
||||
fdt_set_header(fdt, totalsize, bufsize);
|
||||
fdt_set_magic(fdt, SW_MAGIC);
|
||||
fdt_set_version(fdt, FDT_LAST_SUPPORTED_VERSION);
|
||||
fdt_set_last_comp_version(fdt, FDT_FIRST_SUPPORTED_VERSION);
|
||||
fdt_set_totalsize(fdt, bufsize);
|
||||
|
||||
fdt_set_header(fdt, off_mem_rsvmap, ALIGN(sizeof(struct fdt_header),
|
||||
sizeof(struct fdt_reserve_entry)));
|
||||
fdt_set_header(fdt, off_dt_struct, fdt_off_mem_rsvmap(fdt));
|
||||
fdt_set_header(fdt, off_dt_strings, bufsize);
|
||||
fdt_set_off_mem_rsvmap(fdt, ALIGN(sizeof(struct fdt_header),
|
||||
sizeof(struct fdt_reserve_entry)));
|
||||
fdt_set_off_dt_struct(fdt, fdt_off_mem_rsvmap(fdt));
|
||||
fdt_set_off_dt_strings(fdt, bufsize);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size)
|
|||
re->address = cpu_to_fdt64(addr);
|
||||
re->size = cpu_to_fdt64(size);
|
||||
|
||||
fdt_set_header(fdt, off_dt_struct, offset + sizeof(*re));
|
||||
fdt_set_off_dt_struct(fdt, offset + sizeof(*re));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -181,7 +181,7 @@ static int find_add_string(void *fdt, const char *s)
|
|||
return 0; /* no more room :( */
|
||||
|
||||
memcpy(strtab + offset, s, len);
|
||||
fdt_set_header(fdt, size_dt_strings, strtabsize + len);
|
||||
fdt_set_size_dt_strings(fdt, strtabsize + len);
|
||||
return offset;
|
||||
}
|
||||
|
||||
|
@ -231,7 +231,7 @@ int fdt_finish(void *fdt)
|
|||
oldstroffset = fdt_totalsize(fdt) - fdt_size_dt_strings(fdt);
|
||||
newstroffset = fdt_off_dt_struct(fdt) + fdt_size_dt_struct(fdt);
|
||||
memmove(p + newstroffset, p + oldstroffset, fdt_size_dt_strings(fdt));
|
||||
fdt_set_header(fdt, off_dt_strings, newstroffset);
|
||||
fdt_set_off_dt_strings(fdt, newstroffset);
|
||||
|
||||
/* Walk the structure, correcting string offsets */
|
||||
offset = 0;
|
||||
|
@ -252,7 +252,7 @@ int fdt_finish(void *fdt)
|
|||
}
|
||||
|
||||
/* Finally, adjust the header */
|
||||
fdt_set_header(fdt, totalsize, newstroffset + fdt_size_dt_strings(fdt));
|
||||
fdt_set_header(fdt, magic, FDT_MAGIC);
|
||||
fdt_set_totalsize(fdt, newstroffset + fdt_size_dt_strings(fdt));
|
||||
fdt_set_magic(fdt, FDT_MAGIC);
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue