Edward O'Callaghan has submitted this change. ( https://review.coreboot.org/c/flashrom/+/68774 )
Change subject: ichspi.c: heap allocate hwseq_data to remove global ......................................................................
ichspi.c: heap allocate hwseq_data to remove global
Align hwseq path in ichspi with the rest of the flashrom tree by making hwseq_data a heap allocation within the life-time of the driver managed by the driver registration API.
Change-Id: Ib362c5ab2d3e8afee2c3c7d3135cc4414d6bd6c3 Signed-off-by: Edward O'Callaghan quasisec@google.com Reviewed-on: https://review.coreboot.org/c/flashrom/+/68774 Tested-by: build bot (Jenkins) no-reply@coreboot.org Reviewed-by: Felix Singer felixsinger@posteo.net --- M ichspi.c 1 file changed, 35 insertions(+), 6 deletions(-)
Approvals: build bot (Jenkins): Verified Felix Singer: Looks good to me, approved
diff --git a/ichspi.c b/ichspi.c index bbd2c91..b3beaea 100644 --- a/ichspi.c +++ b/ichspi.c @@ -1255,13 +1255,13 @@ return result; }
-static struct hwseq_data { +struct hwseq_data { uint32_t size_comp0; uint32_t size_comp1; uint32_t addr_mask; bool only_4k; uint32_t hsfc_fcycle; -} g_hwseq_data; +};
static struct hwseq_data *get_hwseq_data_from_context(const struct flashctx *flash) { @@ -1591,6 +1591,12 @@ return 0; }
+static int ich_hwseq_shutdown(void *data) +{ + free(data); + return 0; +} + static int ich_spi_send_multicommand(const struct flashctx *flash, struct spi_command *cmds) { @@ -1804,6 +1810,7 @@ .erase = ich_hwseq_block_erase, .read_register = ich_hwseq_read_status, .write_register = ich_hwseq_write_status, + .shutdown = ich_hwseq_shutdown, };
static int init_ich7_spi(void *spibar, enum ich_chipset ich_gen) @@ -1947,7 +1954,8 @@ enum ich_spi_mode ich_spi_mode = ich_auto; size_t num_freg, num_pr, reg_pr0;
- init_chipset_properties(&swseq_data, &g_hwseq_data, &num_freg, &num_pr, ®_pr0, ich_gen); + struct hwseq_data hwseq_data; + init_chipset_properties(&swseq_data, &hwseq_data, &num_freg, &num_pr, ®_pr0, ich_gen);
int ret = get_ich_spi_mode_param(cfg, &ich_spi_mode); if (ret) @@ -2167,16 +2175,20 @@ msg_perr("Could not determine density of flash component %d.\n", 0); return ERROR_FATAL; } - g_hwseq_data.size_comp0 = tmpi; + hwseq_data.size_comp0 = tmpi;
tmpi = getFCBA_component_density(ich_gen, &desc, 1); if (tmpi < 0) { msg_perr("Could not determine density of flash component %d.\n", 1); return ERROR_FATAL; } - g_hwseq_data.size_comp1 = tmpi; + hwseq_data.size_comp1 = tmpi;
- register_opaque_master(&opaque_master_ich_hwseq, &g_hwseq_data); + struct hwseq_data *opaque_hwseq_data = calloc(1, sizeof(struct hwseq_data)); + if (!opaque_hwseq_data) + return ERROR_FATAL; + memcpy(opaque_hwseq_data, &hwseq_data, sizeof(*opaque_hwseq_data)); + register_opaque_master(&opaque_master_ich_hwseq, opaque_hwseq_data); } else { register_spi_master(&spi_master_ich9, NULL); }