Nico Huber has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/31014
Change subject: layout: Add interface to create a dynamically growing layout ......................................................................
layout: Add interface to create a dynamically growing layout
Another interim solution until we have a better internal layout structure (i.e. linked lists).
Change-Id: I0093de58bc7eadc5cd52355937df23c4a6e934ed Signed-off-by: Nico Huber nico.h@gmx.de --- M layout.c M layout.h 2 files changed, 60 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/14/31014/1
diff --git a/layout.c b/layout.c index c589d17..420a3d9 100644 --- a/layout.c +++ b/layout.c @@ -243,3 +243,54 @@ l->entries[i].start, l->entries[i].end, l->entries[i].name); } } + +static size_t dynlayout_size(unsigned int num_entries) +{ + return sizeof(struct dynamic_layout) + num_entries * sizeof(struct romentry); +} + +struct flashrom_layout *new_layout(unsigned int num_entries) +{ + struct dynamic_layout *const dyn = malloc(dynlayout_size(num_entries)); + if (!dyn) { + msg_gerr("Out of memory!\n"); + return NULL; + } + + memset(dyn, 0x00, sizeof(*dyn)); + dyn->base.entries = (void *)((uint8_t *)dyn + sizeof(*dyn)); + dyn->allocated = num_entries; + + return &dyn->base; +} + +int add_layout_entry(struct flashrom_layout **const l, const char *const name, + const size_t start, const size_t end) +{ + struct dynamic_layout *dyn; + + if (!*l) + *l = new_layout(8); + if (!*l) + return -1; + + dyn = (void *)*l; + + if (dyn->base.num_entries >= dyn->allocated) { + const unsigned int allocate = (dyn->allocated ? : 1) * 2; + dyn = realloc(dyn, dynlayout_size(allocate)); + if (!dyn) + return -1; + dyn->base.entries = (void *)((uint8_t *)dyn + sizeof(*dyn)); + dyn->allocated = allocate; + *l = (void *)dyn; + } + + const unsigned int i = dyn->base.num_entries++; + memset(&dyn->base.entries[i], 0x00, sizeof(dyn->base.entries[i])); + dyn->base.entries[i].start = start; + dyn->base.entries[i].end = end; + snprintf(dyn->base.entries[i].name, sizeof(dyn->base.entries[i].name), "%s", name); + + return 0; +} diff --git a/layout.h b/layout.h index a10cbb4..4227e92 100644 --- a/layout.h +++ b/layout.h @@ -54,6 +54,12 @@ struct romentry entry; };
+struct dynamic_layout { + struct flashrom_layout base; + /* number of (pre)allocated entries */ + unsigned int allocated; +}; + struct flashrom_layout *get_global_layout(void); struct flashrom_flashctx; const struct flashrom_layout *get_layout(const struct flashrom_flashctx *const flashctx); @@ -62,4 +68,7 @@
void report_layout(const struct flashrom_layout *);
+struct flashrom_layout *new_layout(unsigned int num_entries); +int add_layout_entry(struct flashrom_layout **, const char *name, size_t start, size_t end); + #endif /* !__LAYOUT_H__ */
Hello Thomas Heijligen, build bot (Jenkins),
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/flashrom/+/31014
to look at the new patch set (#2).
Change subject: layout: Add interface to create a dynamically growing layout ......................................................................
layout: Add interface to create a dynamically growing layout
Another interim solution until we have a better internal layout structure (i.e. linked lists).
Change-Id: I0093de58bc7eadc5cd52355937df23c4a6e934ed Signed-off-by: Nico Huber nico.h@gmx.de --- M layout.c M layout.h 2 files changed, 60 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/14/31014/2
David Hendricks has uploaded a new patch set (#3) to the change originally created by Nico Huber. ( https://review.coreboot.org/c/flashrom/+/31014 )
Change subject: layout: Add interface to create a dynamically growing layout ......................................................................
layout: Add interface to create a dynamically growing layout
Another interim solution until we have a better internal layout structure (i.e. linked lists).
Change-Id: I0093de58bc7eadc5cd52355937df23c4a6e934ed Signed-off-by: Nico Huber nico.h@gmx.de --- M layout.c M layout.h 2 files changed, 60 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/14/31014/3
David Hendricks has posted comments on this change. ( https://review.coreboot.org/c/flashrom/+/31014 )
Change subject: layout: Add interface to create a dynamically growing layout ......................................................................
Patch Set 3: Code-Review-1
(1 comment)
I took a swing at rebasing this patch chain, hopefully we can get it in in the not-too-distant future.
https://review.coreboot.org/c/flashrom/+/31014/3/layout.c File layout.c:
https://review.coreboot.org/c/flashrom/+/31014/3/layout.c@378 PS3, Line 378: snprintf(dyn->base.entries[i].name, sizeof(dyn->base.entries[i].name), "%s", name); This line is what's causing the build failure: layout.c: In function 'add_layout_entry': layout.c:378:44: error: argument to 'sizeof' in 'snprintf' call is the same expression as the destination; did you mean to provide an explicit length? [-Werror=sizeof-pointer-memaccess] snprintf(dyn->base.entries[i].name, sizeof(dyn->base.entries[i].name), "%s", name);
Looking at it a bit more closely, are you sure memory is being allocated for the name string?