Nico Huber merged this change.
layout: Never use global `layout` directly
And rename it to `global_layout` to free `layout` as a local variable
name. We will get rid of the global layout entirely later.
Change-Id: Ia2d7d1f4f649cd239b559ba6a40ee0977004e774
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/33513
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
---
M layout.c
1 file changed, 23 insertions(+), 20 deletions(-)
diff --git a/layout.c b/layout.c
index 52a0c2e..6e34814 100644
--- a/layout.c
+++ b/layout.c
@@ -24,11 +24,11 @@
#include "layout.h"
struct romentry entries[MAX_ROMLAYOUT];
-static struct flashrom_layout layout = { entries, 0 };
+static struct flashrom_layout global_layout = { entries, 0 };
struct flashrom_layout *get_global_layout(void)
{
- return &layout;
+ return &global_layout;
}
const struct flashrom_layout *get_layout(const struct flashrom_flashctx *const flashctx)
@@ -42,6 +42,7 @@
#ifndef __LIBPAYLOAD__
int read_romlayout(const char *name)
{
+ struct flashrom_layout *const layout = get_global_layout();
FILE *romlayout;
char tempstr[256];
int i;
@@ -57,13 +58,13 @@
while (!feof(romlayout)) {
char *tstr1, *tstr2;
- if (layout.num_entries >= MAX_ROMLAYOUT) {
+ if (layout->num_entries >= MAX_ROMLAYOUT) {
msg_gerr("Maximum number of ROM images (%i) in layout "
"file reached.\n", MAX_ROMLAYOUT);
(void)fclose(romlayout);
return 1;
}
- if (2 != fscanf(romlayout, "%255s %255s\n", tempstr, layout.entries[layout.num_entries].name))
+ if (2 != fscanf(romlayout, "%255s %255s\n", tempstr, layout->entries[layout->num_entries].name))
continue;
#if 0
// fscanf does not like arbitrary comments like that :( later
@@ -78,16 +79,16 @@
(void)fclose(romlayout);
return 1;
}
- layout.entries[layout.num_entries].start = strtol(tstr1, (char **)NULL, 16);
- layout.entries[layout.num_entries].end = strtol(tstr2, (char **)NULL, 16);
- layout.entries[layout.num_entries].included = 0;
- layout.num_entries++;
+ layout->entries[layout->num_entries].start = strtol(tstr1, (char **)NULL, 16);
+ layout->entries[layout->num_entries].end = strtol(tstr2, (char **)NULL, 16);
+ layout->entries[layout->num_entries].included = 0;
+ layout->num_entries++;
}
- for (i = 0; i < layout.num_entries; i++) {
+ for (i = 0; i < layout->num_entries; i++) {
msg_gdbg("romlayout %08x - %08x named %s\n",
- layout.entries[i].start,
- layout.entries[i].end, layout.entries[i].name);
+ layout->entries[i].start,
+ layout->entries[i].end, layout->entries[i].name);
}
(void)fclose(romlayout);
@@ -185,6 +186,7 @@
void layout_cleanup(struct layout_include_args **args)
{
+ struct flashrom_layout *const layout = get_global_layout();
int i;
struct layout_include_args *tmp;
@@ -194,29 +196,30 @@
*args = tmp;
}
- for (i = 0; i < layout.num_entries; i++) {
- layout.entries[i].included = 0;
+ for (i = 0; i < layout->num_entries; i++) {
+ layout->entries[i].included = 0;
}
- layout.num_entries = 0;
+ layout->num_entries = 0;
}
/* Validate and - if needed - normalize layout entries. */
int normalize_romentries(const struct flashctx *flash)
{
+ struct flashrom_layout *const layout = get_global_layout();
chipsize_t total_size = flash->chip->total_size * 1024;
int ret = 0;
int i;
- for (i = 0; i < layout.num_entries; i++) {
- if (layout.entries[i].start >= total_size || layout.entries[i].end >= total_size) {
+ for (i = 0; i < layout->num_entries; i++) {
+ if (layout->entries[i].start >= total_size || layout->entries[i].end >= total_size) {
msg_gwarn("Warning: Address range of region \"%s\" exceeds the current chip's "
- "address space.\n", layout.entries[i].name);
- if (layout.entries[i].included)
+ "address space.\n", layout->entries[i].name);
+ if (layout->entries[i].included)
ret = 1;
}
- if (layout.entries[i].start > layout.entries[i].end) {
+ if (layout->entries[i].start > layout->entries[i].end) {
msg_gerr("Error: Size of the address range of region \"%s\" is not positive.\n",
- layout.entries[i].name);
+ layout->entries[i].name);
ret = 1;
}
}
To view, visit change 33513. To unsubscribe, or for help writing mail filters, visit settings.