From 9309bed2906440cfac1257135805fd82c5d8b7a8 Mon Sep 17 00:00:00 2001 From: Anastasia Klimchuk Date: Thu, 13 May 2021 12:28:47 +1000 Subject: 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. BUG=b:185191942 TEST=builds Change-Id: Id3adb4cf04ae04dbe87ddb96f30871cb5f7c8ff0 Signed-off-by: Anastasia Klimchuk Reviewed-on: https://review.coreboot.org/c/flashrom/+/54170 Reviewed-by: Edward O'Callaghan Reviewed-by: Nico Huber Tested-by: build bot (Jenkins) --- ichspi.c | 2 +- linux_mtd.c | 2 +- nicintel_eeprom.c | 4 ++-- opaque.c | 4 +++- programmer.h | 2 +- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/ichspi.c b/ichspi.c index 57cbdeeb..80fcff5e 100644 --- a/ichspi.c +++ b/ichspi.c @@ -2046,7 +2046,7 @@ int ich_init_spi(void *spibar, enum ich_chipset ich_gen) } 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 0f7ac7e6..aeaecce2 100644 --- a/linux_mtd.c +++ b/linux_mtd.c @@ -424,7 +424,7 @@ int linux_mtd_init(void) goto linux_mtd_init_exit; } - register_opaque_master(&programmer_linux_mtd); + register_opaque_master(&programmer_linux_mtd, NULL); ret = 0; linux_mtd_init_exit: diff --git a/nicintel_eeprom.c b/nicintel_eeprom.c index f95107ff..e170fcf4 100644 --- a/nicintel_eeprom.c +++ b/nicintel_eeprom.c @@ -486,7 +486,7 @@ int nicintel_ee_init(void) 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); @@ -496,7 +496,7 @@ int nicintel_ee_init(void) 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 e3103c89..f098ffc1 100644 --- a/opaque.c +++ b/opaque.c @@ -46,7 +46,7 @@ int erase_opaque(struct flashctx *flash, unsigned int blockaddr, unsigned int bl 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 = {0}; @@ -58,5 +58,7 @@ int register_opaque_master(const struct opaque_master *mst) } 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 ac6b0584..790fcc84 100644 --- a/programmer.h +++ b/programmer.h @@ -725,7 +725,7 @@ struct opaque_master { 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); -- cgit v1.2.3