\r
const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int len)\r
{\r
- const char *p;\r
+ unsigned absoffset = offset + fdt_off_dt_struct(fdt);\r
+\r
+ if ((absoffset < offset)\r
+ || ((absoffset + len) < absoffset)\r
+ || (absoffset + len) > fdt_totalsize(fdt))\r
+ return NULL;\r
\r
if (fdt_version(fdt) >= 0x11)\r
if (((offset + len) < offset)\r
|| ((offset + len) > fdt_size_dt_struct(fdt)))\r
return NULL;\r
\r
- p = _fdt_offset_ptr(fdt, offset);\r
-\r
- if (p + len < p)\r
- return NULL;\r
- return p;\r
+ return _fdt_offset_ptr(fdt, offset);\r
}\r
\r
uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)\r
{\r
- const uint32_t *tagp, *lenp;\r
+ const fdt32_t *tagp, *lenp;\r
uint32_t tag;\r
int offset = startoffset;\r
const char *p;\r
return offset;\r
}\r
\r
+int fdt_first_subnode(const void *fdt, int offset)\r
+{\r
+ int depth = 0;\r
+\r
+ offset = fdt_next_node(fdt, offset, &depth);\r
+ if (offset < 0 || depth != 1)\r
+ return -FDT_ERR_NOTFOUND;\r
+\r
+ return offset;\r
+}\r
+\r
+int fdt_next_subnode(const void *fdt, int offset)\r
+{\r
+ int depth = 1;\r
+\r
+ /*\r
+ * With respect to the parent, the depth of the next subnode will be\r
+ * the same as the last.\r
+ */\r
+ do {\r
+ offset = fdt_next_node(fdt, offset, &depth);\r
+ if (offset < 0 || depth < 1)\r
+ return -FDT_ERR_NOTFOUND;\r
+ } while (depth > 1);\r
+\r
+ return offset;\r
+}\r
+\r
const char *_fdt_find_string(const char *strtab, int tabsize, const char *s)\r
{\r
int len = strlen(s) + 1;\r