flashrom.c: Sort initial error checks in create_erase_layout()

With the original order, we might report the wrong error in case
calloc() returns `NULL` for `nmemb == 0`.

Change-Id: If1330ab1cbde817fb7ef91f7dc6ace219cb6ecbc
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.coreboot.org/c/flashrom-stable/+/72555
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 53693ff..b8d3a0a 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -1011,18 +1011,18 @@
 {
 	const struct flashchip *chip = flashctx->chip;
 	const size_t erasefn_count = count_usable_erasers(flashctx);
-	struct erase_layout *layout = calloc(erasefn_count, sizeof(struct erase_layout));
-
-	if (!layout) {
-		msg_gerr("Out of memory!\n");
-		return -1;
-	}
 
 	if (!erasefn_count) {
 		msg_gerr("No erase functions supported\n");
 		return 0;
 	}
 
+	struct erase_layout *layout = calloc(erasefn_count, sizeof(struct erase_layout));
+	if (!layout) {
+		msg_gerr("Out of memory!\n");
+		return -1;
+	}
+
 	size_t layout_idx = 0;
 	for (size_t eraser_idx = 0; eraser_idx < NUM_ERASEFUNCTIONS; eraser_idx++) {
 		if (check_block_eraser(flashctx, eraser_idx, 0))