summaryrefslogtreecommitdiffstats
path: root/ich_descriptors.c
diff options
context:
space:
mode:
authorNico Huber <nico.h@gmx.de>2019-06-16 19:46:46 +0200
committerNico Huber <nico.h@gmx.de>2021-06-26 15:54:51 +0000
commitc32c8dc8af9e971f91feaee145f1e8d6f114cad6 (patch)
tree08094ba25f338f3ab83451edec8352333fdc9c5e /ich_descriptors.c
parentf394fcec0da2fd4a9d1bd7a7911065344e67ce34 (diff)
downloadflashrom-c32c8dc8af9e971f91feaee145f1e8d6f114cad6.tar.gz
flashrom-c32c8dc8af9e971f91feaee145f1e8d6f114cad6.tar.bz2
flashrom-c32c8dc8af9e971f91feaee145f1e8d6f114cad6.zip
layout: Introduce flashrom_layout_new()
It initializes an empty layout. Currently the maximum number of entries has to be specified, which will vanish once we use dynamic allocation per entry. We replace the two special cases `single_layout` and `ich_layout` with dynamically allocated layouts. As a result, we have to take care to release the `default_layout` in a flashctx once we are done with it. Change-Id: I2ae7246493ff592e631cce924777925c7825e398 Signed-off-by: Nico Huber <nico.h@gmx.de> Reviewed-on: https://review.coreboot.org/c/flashrom/+/33543 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Edward O'Callaghan <quasisec@chromium.org> Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Diffstat (limited to 'ich_descriptors.c')
-rw-r--r--ich_descriptors.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/ich_descriptors.c b/ich_descriptors.c
index ad1a88b64..5e6c7fb53 100644
--- a/ich_descriptors.c
+++ b/ich_descriptors.c
@@ -1261,7 +1261,9 @@ int read_ich_descriptors_via_fdo(enum ich_chipset cs, void *spibar, struct ich_d
* 1 if the descriptor couldn't be parsed,
* 2 when out of memory.
*/
-int layout_from_ich_descriptors(struct ich_layout *const layout, const void *const dump, const size_t len)
+int layout_from_ich_descriptors(
+ struct flashrom_layout **const layout,
+ const void *const dump, const size_t len)
{
static const char *const regions[] = {
"fd", "bios", "me", "gbe", "pd", "reg5", "bios2", "reg7", "ec", "reg9", "ie",
@@ -1277,10 +1279,8 @@ int layout_from_ich_descriptors(struct ich_layout *const layout, const void *con
return 1;
}
- memset(layout, 0x00, sizeof(*layout));
- layout->base.entries = layout->entries;
- layout->base.capacity = ARRAY_SIZE(layout->entries);
- layout->base.num_entries = 0;
+ if (flashrom_layout_new(layout, ARRAY_SIZE(regions)))
+ return 2;
ssize_t i;
const ssize_t nr = MIN(ich_number_of_regions(cs, &desc.content), (ssize_t)ARRAY_SIZE(regions));
@@ -1289,8 +1289,11 @@ int layout_from_ich_descriptors(struct ich_layout *const layout, const void *con
const chipoff_t limit = ICH_FREG_LIMIT(desc.region.FLREGs[i]);
if (limit <= base)
continue;
- if (flashrom_layout_add_region(&layout->base, base, limit, regions[i]))
+ if (flashrom_layout_add_region(*layout, base, limit, regions[i])) {
+ flashrom_layout_release(*layout);
+ *layout = NULL;
return 2;
+ }
}
return 0;
}