Nico Huber has uploaded this change for review.

View Change

libflashrom: Fix comparison of layout entries

A `next` pointer was added to `struct romentry` in commit 953c5ad44058
(layout: Use linked list for `struct romentry`). Hence, comparing the
whole contents to match entries doesn't work anymore. Solve that by
comparing the `start`, `end` and `name` fields individually.

The introduced layout_cmp() function could be made a new API, but
that's not necessary for the release branch.

Change-Id: I125d3892d9efc68e8fc19eef559c82d46c3bdc94
Signed-off-by: Nico Huber <nico.h@gmx.de>
---
M libflashrom.c
1 file changed, 34 insertions(+), 1 deletion(-)

git pull ssh://review.coreboot.org:29418/flashrom refs/changes/33/72433/1
diff --git a/libflashrom.c b/libflashrom.c
index ce9d351..60edb66 100644
--- a/libflashrom.c
+++ b/libflashrom.c
@@ -266,6 +266,21 @@
}
}

+static int layout_cmp(const struct romentry *const a, const struct romentry *const b)
+{
+ int ret;
+
+ ret = (int)a->start - (int)b->start;
+ if (ret)
+ return ret;
+
+ ret = (int)a->end - (int)b->end;
+ if (ret)
+ return ret;
+
+ return strcmp(a->name, b->name);
+}
+
int flashrom_layout_read_from_ifd(struct flashrom_layout **const layout, struct flashctx *const flashctx,
const void *const dump, const size_t len)
{
@@ -303,7 +318,7 @@

const struct romentry *chip_entry = layout_next(chip_layout, NULL);
const struct romentry *dump_entry = layout_next(dump_layout, NULL);
- while (chip_entry && dump_entry && !memcmp(chip_entry, dump_entry, sizeof(*chip_entry))) {
+ while (chip_entry && dump_entry && !layout_cmp(chip_entry, dump_entry)) {
chip_entry = layout_next(chip_layout, chip_entry);
dump_entry = layout_next(dump_layout, dump_entry);
}

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

Gerrit-Project: flashrom
Gerrit-Branch: 1.3.x
Gerrit-Change-Id: I125d3892d9efc68e8fc19eef559c82d46c3bdc94
Gerrit-Change-Number: 72433
Gerrit-PatchSet: 1
Gerrit-Owner: Nico Huber <nico.h@gmx.de>
Gerrit-MessageType: newchange