flashrom.c: Rewrite calculate_block_count()
There is not need to do address calculations in calculate_block_count().
We only want to return the final count, so only add that up. As a bonus,
we only need to pass the eraser and not the whole chip reference.
Change-Id: I0cdfaad85aeda90513268d08da47acbe72ca57e5
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.coreboot.org/c/flashrom-stable/+/72553
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Arthur Heymans <arthur@aheymans.xyz>
diff --git a/flashrom.c b/flashrom.c
index 1301f04..02e47e1 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -942,16 +942,12 @@
return !info->newcontents;
}
-static size_t calculate_block_count(const struct flashchip *chip, size_t eraser_idx)
+static size_t calculate_block_count(const struct block_eraser *const eraser)
{
- size_t block_count = 0;
+ size_t block_count = 0, i;
- chipoff_t addr = 0;
- for (size_t i = 0; addr < chip->total_size * 1024; i++) {
- const struct eraseblock *block = &chip->block_erasers[eraser_idx].eraseblocks[i];
- block_count += block->count;
- addr += block->size * block->count;
- }
+ for (i = 0; i < ARRAY_SIZE(eraser->eraseblocks); ++i)
+ block_count += eraser->eraseblocks[i].count;
return block_count;
}
@@ -1031,7 +1027,7 @@
continue;
layout[layout_idx].eraser = &chip->block_erasers[eraser_idx];
- const size_t block_count = calculate_block_count(flashctx->chip, eraser_idx);
+ const size_t block_count = calculate_block_count(&chip->block_erasers[eraser_idx]);
size_t sub_block_index = 0;
layout[layout_idx].block_count = block_count;