Anastasia Klimchuk 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, 16 insertions(+), 1 deletion(-)

git pull ssh://review.coreboot.org:29418/flashrom refs/changes/01/85201/1
diff --git a/libflashrom.c b/libflashrom.c
index dfc86e6..3961e24 100644
--- a/libflashrom.c
+++ b/libflashrom.c
@@ -306,6 +306,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)
{
@@ -343,7 +358,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 85201. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: newchange
Gerrit-Project: flashrom
Gerrit-Branch: main
Gerrit-Change-Id: I125d3892d9efc68e8fc19eef559c82d46c3bdc94
Gerrit-Change-Number: 85201
Gerrit-PatchSet: 1
Gerrit-Owner: Anastasia Klimchuk <aklm@chromium.org>