mirror of
https://review.coreboot.org/flashrom.git
synced 2025-04-27 23:22:37 +02:00
layout: Add capacity
field
Use it to keep track of the size of the `entries` array. An interim solution until we have dynamic allocation. Change-Id: Ib5f431bc0a72a79a53fa1376c3417942b19dd3a0 Signed-off-by: Nico Huber <nico.h@gmx.de> Reviewed-on: https://review.coreboot.org/c/flashrom/+/33516 Reviewed-by: Angel Pons <th3fanbus@gmail.com> Reviewed-by: Anastasia Klimchuk <aklm@chromium.org> Reviewed-by: Peter Marheine <pmarheine@chromium.org> Reviewed-by: Edward O'Callaghan <quasisec@chromium.org> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
parent
06a89d7139
commit
7ebd578100
@ -825,6 +825,7 @@ notfound:
|
|||||||
/* Fill fallback layout covering the whole chip. */
|
/* Fill fallback layout covering the whole chip. */
|
||||||
struct single_layout *const fallback = &flash->fallback_layout;
|
struct single_layout *const fallback = &flash->fallback_layout;
|
||||||
fallback->base.entries = &fallback->entry;
|
fallback->base.entries = &fallback->entry;
|
||||||
|
fallback->base.capacity = 1;
|
||||||
fallback->base.num_entries = 1;
|
fallback->base.num_entries = 1;
|
||||||
fallback->entry.start = 0;
|
fallback->entry.start = 0;
|
||||||
fallback->entry.end = flash->chip->total_size * 1024 - 1;
|
fallback->entry.end = flash->chip->total_size * 1024 - 1;
|
||||||
|
@ -1295,6 +1295,7 @@ int layout_from_ich_descriptors(struct ich_layout *const layout, const void *con
|
|||||||
++j;
|
++j;
|
||||||
}
|
}
|
||||||
layout->base.entries = layout->entries;
|
layout->base.entries = layout->entries;
|
||||||
|
layout->base.capacity = ARRAY_SIZE(layout->entries);
|
||||||
layout->base.num_entries = j;
|
layout->base.num_entries = j;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
8
layout.c
8
layout.c
@ -26,7 +26,7 @@
|
|||||||
#include "layout.h"
|
#include "layout.h"
|
||||||
|
|
||||||
static struct romentry entries[MAX_ROMLAYOUT];
|
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)
|
struct flashrom_layout *get_global_layout(void)
|
||||||
{
|
{
|
||||||
@ -87,9 +87,9 @@ int read_romlayout(const char *name)
|
|||||||
while (!feof(romlayout)) {
|
while (!feof(romlayout)) {
|
||||||
char *tstr1, *tstr2;
|
char *tstr1, *tstr2;
|
||||||
|
|
||||||
if (layout->num_entries >= MAX_ROMLAYOUT) {
|
if (layout->num_entries >= layout->capacity) {
|
||||||
msg_gerr("Maximum number of ROM images (%i) in layout "
|
msg_gerr("Maximum number of ROM images (%zu) in layout "
|
||||||
"file reached.\n", MAX_ROMLAYOUT);
|
"file reached.\n", layout->capacity);
|
||||||
goto _close_ret;
|
goto _close_ret;
|
||||||
}
|
}
|
||||||
if (2 != fscanf(romlayout, "%255s %255s\n", tempstr, tempname))
|
if (2 != fscanf(romlayout, "%255s %255s\n", tempstr, tempname))
|
||||||
|
2
layout.h
2
layout.h
@ -46,6 +46,8 @@ struct romentry {
|
|||||||
struct flashrom_layout {
|
struct flashrom_layout {
|
||||||
/* entries store the entries specified in a layout file and associated run-time data */
|
/* entries store the entries specified in a layout file and associated run-time data */
|
||||||
struct romentry *entries;
|
struct romentry *entries;
|
||||||
|
/* the maximum number of entries */
|
||||||
|
size_t capacity;
|
||||||
/* the number of successfully parsed entries */
|
/* the number of successfully parsed entries */
|
||||||
size_t num_entries;
|
size_t num_entries;
|
||||||
};
|
};
|
||||||
|
@ -506,7 +506,7 @@ static int flashrom_layout_parse_fmap(struct flashrom_layout **layout,
|
|||||||
if (!fmap || !l)
|
if (!fmap || !l)
|
||||||
return 1;
|
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");
|
msg_gerr("Cannot add fmap entries to layout - Too many entries.\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user