summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--flashrom.c1
-rw-r--r--ich_descriptors.c1
-rw-r--r--layout.c8
-rw-r--r--layout.h2
-rw-r--r--libflashrom.c2
5 files changed, 9 insertions, 5 deletions
diff --git a/flashrom.c b/flashrom.c
index 90e186435..8d260cb88 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -825,6 +825,7 @@ notfound:
/* Fill fallback layout covering the whole chip. */
struct single_layout *const fallback = &flash->fallback_layout;
fallback->base.entries = &fallback->entry;
+ fallback->base.capacity = 1;
fallback->base.num_entries = 1;
fallback->entry.start = 0;
fallback->entry.end = flash->chip->total_size * 1024 - 1;
diff --git a/ich_descriptors.c b/ich_descriptors.c
index 4ae3a1b87..143e39204 100644
--- a/ich_descriptors.c
+++ b/ich_descriptors.c
@@ -1295,6 +1295,7 @@ int layout_from_ich_descriptors(struct ich_layout *const layout, const void *con
++j;
}
layout->base.entries = layout->entries;
+ layout->base.capacity = ARRAY_SIZE(layout->entries);
layout->base.num_entries = j;
return 0;
}
diff --git a/layout.c b/layout.c
index 2446e8f02..0771d42f6 100644
--- a/layout.c
+++ b/layout.c
@@ -26,7 +26,7 @@
#include "layout.h"
static struct romentry entries[MAX_ROMLAYOUT];
-static struct flashrom_layout global_layout = { entries, 0 };
+static struct flashrom_layout global_layout = { entries, MAX_ROMLAYOUT, 0 };
struct flashrom_layout *get_global_layout(void)
{
@@ -87,9 +87,9 @@ int read_romlayout(const char *name)
while (!feof(romlayout)) {
char *tstr1, *tstr2;
- if (layout->num_entries >= MAX_ROMLAYOUT) {
- msg_gerr("Maximum number of ROM images (%i) in layout "
- "file reached.\n", MAX_ROMLAYOUT);
+ if (layout->num_entries >= layout->capacity) {
+ msg_gerr("Maximum number of ROM images (%zu) in layout "
+ "file reached.\n", layout->capacity);
goto _close_ret;
}
if (2 != fscanf(romlayout, "%255s %255s\n", tempstr, tempname))
diff --git a/layout.h b/layout.h
index d60c89ee3..2a0f8697c 100644
--- a/layout.h
+++ b/layout.h
@@ -46,6 +46,8 @@ struct romentry {
struct flashrom_layout {
/* entries store the entries specified in a layout file and associated run-time data */
struct romentry *entries;
+ /* the maximum number of entries */
+ size_t capacity;
/* the number of successfully parsed entries */
size_t num_entries;
};
diff --git a/libflashrom.c b/libflashrom.c
index c6a598b60..2a39a80dd 100644
--- a/libflashrom.c
+++ b/libflashrom.c
@@ -506,7 +506,7 @@ static int flashrom_layout_parse_fmap(struct flashrom_layout **layout,
if (!fmap || !l)
return 1;
- if (l->num_entries + fmap->nareas > MAX_ROMLAYOUT) {
+ if (l->num_entries + fmap->nareas > l->capacity) {
msg_gerr("Cannot add fmap entries to layout - Too many entries.\n");
return 1;
}