summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdward O'Callaghan <quasisec@chromium.org>2019-11-26 23:31:06 +1100
committerEdward O'Callaghan <quasisec@chromium.org>2019-11-28 10:00:21 +0000
commit1d80d645875cde4aa1ea17bd1d166619bed09682 (patch)
treef40bdbc0af4782ffc5c91fb0b7b986268d3bca2b
parent4a55e6885816aa2a45314975686356ce282cae5c (diff)
downloadflashrom-1d80d645875cde4aa1ea17bd1d166619bed09682.tar.gz
flashrom-1d80d645875cde4aa1ea17bd1d166619bed09682.tar.bz2
flashrom-1d80d645875cde4aa1ea17bd1d166619bed09682.zip
cbtable.c: Factor out lb_table_validation logic
Write a pure function for the table validation logic, it is easier to unit-test. Change-Id: I07b0f95ec0443fa6a8f54eb93f4a7ea1875cccad Signed-off-by: Edward O'Callaghan <quasisec@chromium.org> Reviewed-on: https://review.coreboot.org/c/flashrom/+/37239 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
-rw-r--r--cbtable.c28
1 files changed, 18 insertions, 10 deletions
diff --git a/cbtable.c b/cbtable.c
index 669a4619d..e5668404d 100644
--- a/cbtable.c
+++ b/cbtable.c
@@ -170,6 +170,23 @@ static int lb_header_valid(struct lb_header *head, unsigned long addr)
return 1;
}
+static int lb_table_valid(struct lb_header *head, struct lb_record *recs)
+{
+ if (compute_checksum(recs, head->table_bytes)
+ != head->table_checksum) {
+ msg_perr("Bad table checksum: %04x.\n",
+ head->table_checksum);
+ return 0;
+ }
+ if (count_lb_records(head) != head->table_entries) {
+ msg_perr("Bad record count: %d.\n",
+ head->table_entries);
+ return 0;
+ }
+
+ return 1;
+}
+
static struct lb_header *find_lb_table(void *base, unsigned long start,
unsigned long end)
{
@@ -183,17 +200,8 @@ static struct lb_header *find_lb_table(void *base, unsigned long start,
(struct lb_record *)(((char *)base) + addr + sizeof(*head));
if (!lb_header_valid(head, addr))
continue;
- if (count_lb_records(head) != head->table_entries) {
- msg_perr("Bad record count: %d.\n",
- head->table_entries);
+ if (!lb_table_valid(head, recs))
continue;
- }
- if (compute_checksum(recs, head->table_bytes)
- != head->table_checksum) {
- msg_perr("Bad table checksum: %04x.\n",
- head->table_checksum);
- continue;
- }
msg_pdbg("Found coreboot table at 0x%08lx.\n", addr);
return head;