layout.c: Don't use global variables for included regions

This removes the use of global variables for included region arguments
and also uses a linked list to store the arguments.

Change-Id: I6534cc58b8dcc6256c2730c809286d8083669a6c
Signed-off-by: Arthur Heymans <arthur@aheymans.xyz>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/31247
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Nico Huber <nico.h@gmx.de>
diff --git a/cli_classic.c b/cli_classic.c
index ced08c6..2e07612 100644
--- a/cli_classic.c
+++ b/cli_classic.c
@@ -151,6 +151,7 @@
 #endif /* !STANDALONE */
 	char *tempstr = NULL;
 	char *pparam = NULL;
+	struct layout_include_args *include_args = NULL;
 
 	flashrom_set_log_callback((flashrom_log_callback *)&flashrom_print_cb);
 
@@ -290,7 +291,7 @@
 			break;
 		case 'i':
 			tempstr = strdup(optarg);
-			if (register_include_arg(tempstr)) {
+			if (register_include_arg(&include_args, tempstr)) {
 				free(tempstr);
 				cli_classic_abort_usage();
 			}
@@ -452,7 +453,7 @@
 		goto out;
 	}
 
-	if (!ifd && !fmap && process_include_args(get_global_layout())) {
+	if (!ifd && !fmap && process_include_args(get_global_layout(), include_args)) {
 		ret = 1;
 		goto out;
 	}
@@ -608,7 +609,7 @@
 	if (layoutfile) {
 		layout = get_global_layout();
 	} else if (ifd && (flashrom_layout_read_from_ifd(&layout, fill_flash, NULL, 0) ||
-			   process_include_args(layout))) {
+			   process_include_args(layout, include_args))) {
 		ret = 1;
 		goto out_shutdown;
 	} else if (fmap && fmapfile) {
@@ -633,14 +634,14 @@
 		}
 
 		if (flashrom_layout_read_fmap_from_buffer(&layout, fill_flash, fmapfile_buffer, fmapfile_size) ||
-				process_include_args(layout)) {
+		    process_include_args(layout, include_args)) {
 			ret = 1;
 			free(fmapfile_buffer);
 			goto out_shutdown;
 		}
 		free(fmapfile_buffer);
 	} else if (fmap && (flashrom_layout_read_fmap_from_rom(&layout, fill_flash, 0,
-				fill_flash->chip->total_size * 1024) || process_include_args(layout))) {
+		       fill_flash->chip->total_size * 1024) || process_include_args(layout, include_args))) {
 		ret = 1;
 		goto out_shutdown;
 	}
@@ -675,7 +676,7 @@
 	for (i = 0; i < chipcount; i++)
 		free(flashes[i].chip);
 
-	layout_cleanup();
+	layout_cleanup(&include_args);
 	free(filename);
 	free(fmapfile);
 	free(referencefile);