static int fdtgrep_find_regions(const void *fdt, int (*include_func)(void *priv, const void *fdt, int offset, int type, const char *data, int size), struct display_info *disp, struct fdt_region *region, int max_regions, char *path, int path_len, int flags) { struct fdt_region_state state; int count; int ret; count = 0; ret = fdt_first_region(fdt, include_func, disp, ®ion[count++], path, path_len, disp->flags, &state); while (ret == 0) { ret = fdt_next_region(fdt, include_func, disp, count < max_regions ? ®ion[count] : NULL, path, path_len, disp->flags, &state); if (!ret) count++; } if (ret && ret != -FDT_ERR_NOTFOUND) return ret; /* Find all the aliases and add those regions back in */ if (disp->add_aliases && count < max_regions) { int new_count; new_count = fdt_add_alias_regions(fdt, region, count, max_regions, &state); if (new_count == -FDT_ERR_NOTFOUND) { /* No alias node found */ } else if (new_count < 0) { return new_count; } else if (new_count <= max_regions) { /* * The alias regions will now be at the end of the list. * Sort the regions by offset to get things into the * right order */ count = new_count; qsort(region, count, sizeof(struct fdt_region), h_cmp_region); } } return count; }
/** * check_regions() - Check that the regions are as we expect * * Call fdt_find_regions() and check that the results are as we expect them, * matching the list of expected regions we created at the same time as * the tree. * * @fdt: Pointer to device tree to check * @flags: Flags value (FDT_REG_...) * @return 0 if ok, -1 on failure */ static int check_regions(const void *fdt, int flags) { struct fdt_region_state state; struct fdt_region reg; int err, ret = 0; char path[1024]; int count; int i; ret = fdt_first_region(fdt, h_include, NULL, ®, path, sizeof(path), flags, &state); if (ret < 0) CHECK(ret); verbose_printf("Regions: %d\n", count); for (i = 0; ; i++) { struct fdt_region *exp = &expect[i]; verbose_printf("%d: %-10x %-10x\n", i, reg.offset, reg.offset + reg.size); if (memcmp(exp, ®, sizeof(reg))) { ret = -1; verbose_printf("exp: %-10x %-10x\n", exp->offset, exp->offset + exp->size); } ret = fdt_next_region(fdt, h_include, NULL, ®, path, sizeof(path), flags, &state); if (ret < 0) { if (ret == -FDT_ERR_NOTFOUND) ret = 0; CHECK(ret); i++; break; } } verbose_printf("expect_count = %d, i=%d\n", expect_count, i); if (expect_count != i) FAIL(); return ret; }