programmer: Smoothen register_opaque_master() API

It was impossible to register a const struct opaque_master that would
point to dynamically allocated `data`. Fix that so that we won't
have to create more mutable globals.

Change-Id: Id3adb4cf04ae04dbe87ddb96f30871cb5f7c8ff0
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Original-Reviewed-on: https://review.coreboot.org/c/flashrom/+/54170
Original-Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
Original-Reviewed-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.coreboot.org/c/flashrom-stable/+/72202
Reviewed-by: Nico Huber <nico.h@gmx.de>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
diff --git a/ichspi.c b/ichspi.c
index 929dcc4..c76b708 100644
--- a/ichspi.c
+++ b/ichspi.c
@@ -2060,7 +2060,7 @@
 			}
 			hwseq_data.size_comp1 = tmpi;
 
-			register_opaque_master(&opaque_master_ich_hwseq);
+			register_opaque_master(&opaque_master_ich_hwseq, NULL);
 		} else {
 			register_spi_master(&spi_master_ich9, NULL);
 		}
diff --git a/linux_mtd.c b/linux_mtd.c
index 125de6b..6a9257f 100644
--- a/linux_mtd.c
+++ b/linux_mtd.c
@@ -426,7 +426,7 @@
 		goto linux_mtd_init_exit;
 	}
 
-	register_opaque_master(&linux_mtd_opaque_master);
+	register_opaque_master(&linux_mtd_opaque_master, NULL);
 
 	ret = 0;
 linux_mtd_init_exit:
diff --git a/nicintel_eeprom.c b/nicintel_eeprom.c
index 0b20290..33c0b0f 100644
--- a/nicintel_eeprom.c
+++ b/nicintel_eeprom.c
@@ -490,7 +490,7 @@
 				return 1;
 		}
 
-		return register_opaque_master(&opaque_master_nicintel_ee_82580);
+		return register_opaque_master(&opaque_master_nicintel_ee_82580, NULL);
 	} else {
 		nicintel_eebar = rphysmap("Intel i210 NIC w/ emulated EEPROM",
 					  io_base_addr + 0x12000, MEMMAP_SIZE);
@@ -500,7 +500,7 @@
 		if (register_shutdown(nicintel_ee_shutdown_i210, NULL))
 			return 1;
 
-		return register_opaque_master(&opaque_master_nicintel_ee_i210);
+		return register_opaque_master(&opaque_master_nicintel_ee_i210, NULL);
 	}
 
 	return 1;
diff --git a/opaque.c b/opaque.c
index ab39100..a3e0465 100644
--- a/opaque.c
+++ b/opaque.c
@@ -46,7 +46,7 @@
 	return flash->mst->opaque.erase(flash, blockaddr, blocklen);
 }
 
-int register_opaque_master(const struct opaque_master *mst)
+int register_opaque_master(const struct opaque_master *mst, void *data)
 {
 	struct registered_master rmst;
 
@@ -58,5 +58,7 @@
 	}
 	rmst.buses_supported = BUS_PROG;
 	rmst.opaque = *mst;
+	if (data)
+		rmst.opaque.data = data;
 	return register_master(&rmst);
 }
diff --git a/programmer.h b/programmer.h
index 7134b94..97c3a8a 100644
--- a/programmer.h
+++ b/programmer.h
@@ -403,7 +403,7 @@
 	int (*erase) (struct flashctx *flash, unsigned int blockaddr, unsigned int blocklen);
 	void *data;
 };
-int register_opaque_master(const struct opaque_master *mst);
+int register_opaque_master(const struct opaque_master *mst, void *data);
 
 /* programmer.c */
 void *fallback_map(const char *descr, uintptr_t phys_addr, size_t len);