Nico Huber would like Angel Pons, Arthur Heymans, David Hendricks and Thomas Heijligen to review this change.

View Change

layout: Introduce layout_next()

And use it to compare the layouts in flashrom_layout_read_from_ifd()
in depth.

Change-Id: I284958471c61344d29d92c95d88475065a9ca9aa
Signed-off-by: Nico Huber <nico.h@gmx.de>
---
M layout.c
M layout.h
M libflashrom.c
3 files changed, 20 insertions(+), 7 deletions(-)

git pull ssh://review.coreboot.org:29418/flashrom refs/changes/42/33542/1
diff --git a/layout.c b/layout.c
index e49189e..684615c 100644
--- a/layout.c
+++ b/layout.c
@@ -252,7 +252,7 @@
return lowest;
}

-const struct romentry *layout_next_included(
+const struct romentry *layout_next(
const struct flashrom_layout *const layout, const struct romentry *iterator)
{
const struct romentry *const end = layout->entries + layout->num_entries;
@@ -262,14 +262,21 @@
else
iterator = &layout->entries[0];

- for (; iterator < end; ++iterator) {
- if (!iterator->included)
- continue;
+ if (iterator < end)
return iterator;
- }
return NULL;
}

+const struct romentry *layout_next_included(
+ const struct flashrom_layout *const layout, const struct romentry *iterator)
+{
+ while ((iterator = layout_next(layout, iterator))) {
+ if (iterator->included)
+ break;
+ }
+ return iterator;
+}
+
/**
* @addtogroup flashrom-layout
* @{
diff --git a/layout.h b/layout.h
index 53a20d6..f5444e2 100644
--- a/layout.h
+++ b/layout.h
@@ -66,5 +66,6 @@
int process_include_args(struct flashrom_layout *l, const struct layout_include_args *const args);
const struct romentry *layout_next_included_region(const struct flashrom_layout *, chipoff_t);
const struct romentry *layout_next_included(const struct flashrom_layout *, const struct romentry *);
+const struct romentry *layout_next(const struct flashrom_layout *, const struct romentry *);

#endif /* !__LAYOUT_H__ */
diff --git a/libflashrom.c b/libflashrom.c
index af62002..6743d50 100644
--- a/libflashrom.c
+++ b/libflashrom.c
@@ -345,8 +345,13 @@
goto _finalize_ret;
}

- if (chip_layout->base.num_entries != dump_layout.base.num_entries ||
- memcmp(chip_layout->entries, dump_layout.entries, sizeof(dump_layout.entries))) {
+ const struct romentry *chip_entry = layout_next(&chip_layout->base, NULL);
+ const struct romentry *dump_entry = layout_next(&dump_layout.base, NULL);
+ while (chip_entry && dump_entry && !memcmp(chip_entry, dump_entry, sizeof(*chip_entry))) {
+ chip_entry = layout_next(&chip_layout->base, chip_entry);
+ dump_entry = layout_next(&dump_layout.base, dump_entry);
+ }
+ if (chip_entry || dump_entry) {
msg_cerr("Descriptors don't match!\n");
ret = 5;
goto _finalize_ret;

To view, visit change 33542. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I284958471c61344d29d92c95d88475065a9ca9aa
Gerrit-Change-Number: 33542
Gerrit-PatchSet: 1
Gerrit-Owner: Nico Huber <nico.h@gmx.de>
Gerrit-Reviewer: Angel Pons <th3fanbus@gmail.com>
Gerrit-Reviewer: Arthur Heymans <arthur@aheymans.xyz>
Gerrit-Reviewer: David Hendricks <david.hendricks@gmail.com>
Gerrit-Reviewer: Thomas Heijligen <src@posteo.de>
Gerrit-MessageType: newchange