From ef5ebdb5bb6de81b703cc13d95e9a634ba311b8c Mon Sep 17 00:00:00 2001 From: Patrick Rudolph Date: Sat, 22 Oct 2022 11:19:02 +0200 Subject: [PATCH] ifdtool: Introduce region_name_fmap Instead of directly accessing the region_name array use a helper function. This allows to move the region name array to a separate file. Change-Id: Ifc810da1628cebd2728d0185502c462ff9428597 Signed-off-by: Patrick Rudolph Reviewed-on: https://review.coreboot.org/c/coreboot/+/68694 Tested-by: build bot (Jenkins) Reviewed-by: Lean Sheng Tan --- util/ifdtool/ifdtool.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/util/ifdtool/ifdtool.c b/util/ifdtool/ifdtool.c index 61aedf53ef..98afa4bbcf 100644 --- a/util/ifdtool/ifdtool.c +++ b/util/ifdtool/ifdtool.c @@ -361,6 +361,16 @@ static const char *region_name(unsigned int region_type) return region_names[region_type].pretty; } +static const char *region_name_fmap(unsigned int region_type) +{ + if (region_type >= max_regions) { + fprintf(stderr, "Invalid region type.\n"); + exit(EXIT_FAILURE); + } + + return region_names[region_type].fmapname; +} + static const char *region_name_short(unsigned int region_type) { if (region_type >= max_regions) { @@ -1073,7 +1083,7 @@ static void validate_layout(char *image, int size) fmap = (struct fmap *)(image + fmap_loc); for (i = 0; i < max_regions; i++) { - if (region_names[i].fmapname == NULL) + if (region_name_fmap(i) == NULL) continue; region_t region = get_region(frba, i); @@ -1082,7 +1092,7 @@ static void validate_layout(char *image, int size) continue; const struct fmap_area *area = - fmap_find_area(fmap, region_names[i].fmapname); + fmap_find_area(fmap, region_name_fmap(i)); if (!area) continue;