diff options
author | Edward O'Callaghan <quasisec@google.com> | 2021-01-06 14:10:52 +1100 |
---|---|---|
committer | Edward O'Callaghan <quasisec@chromium.org> | 2021-01-17 07:00:05 +0000 |
commit | ec942500661f01fa9ac95797e1878a749a94a586 (patch) | |
tree | 0e116aff42b5958133ae8f8c1297524bb6d91a35 /bitbang_spi.c | |
parent | 4f112f699485006f22c988a37961544141905f27 (diff) | |
download | flashrom-ec942500661f01fa9ac95797e1878a749a94a586.tar.gz flashrom-ec942500661f01fa9ac95797e1878a749a94a586.tar.bz2 flashrom-ec942500661f01fa9ac95797e1878a749a94a586.zip |
tree/: Drop const from opaque data ptr in master definitions [alt]
The opaque data pointer need not necessarily have constant
data for the life-time of the specific master. This is because
the data field purpose is for the master to use as it sees fit
for managing its own internal state and therefore we should not
constrain this as being RO data at init time.
BUG=none
BRANCH=none
TEST=builds
Change-Id: I686c3c79547e35d48f3fd0b524fc98c176dcea6e
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/49131
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Sam McNally <sammc@google.com>
Diffstat (limited to 'bitbang_spi.c')
-rw-r--r-- | bitbang_spi.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/bitbang_spi.c b/bitbang_spi.c index c4021197..b12d81ac 100644 --- a/bitbang_spi.c +++ b/bitbang_spi.c @@ -94,13 +94,18 @@ static void bitbang_spi_write_byte(const struct bitbang_spi_master *master, uint } } +struct bitbang_spi_master_data { + const struct bitbang_spi_master *mst; +}; + static int bitbang_spi_send_command(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr) { unsigned int i; - const struct bitbang_spi_master *master = flash->mst->spi.data; + const struct bitbang_spi_master_data *data = flash->mst->spi.data; + const struct bitbang_spi_master *master = data->mst; /* FIXME: Run bitbang_spi_request_bus here or in programmer init? * Requesting and releasing the SPI bus is handled in here to allow the @@ -134,13 +139,12 @@ static const struct spi_master spi_master_bitbang = { .write_aai = default_spi_write_aai, }; -#if 0 // until it is needed -static int bitbang_spi_shutdown(const struct bitbang_spi_master *master) +static int bitbang_spi_shutdown(void *data) { /* FIXME: Run bitbang_spi_release_bus here or per command? */ + free(data); return 0; } -#endif int register_spi_bitbang_master(const struct bitbang_spi_master *master) { @@ -155,8 +159,11 @@ int register_spi_bitbang_master(const struct bitbang_spi_master *master) return ERROR_FLASHROM_BUG; } - mst.data = master; + struct bitbang_spi_master_data *data = calloc(1, sizeof(struct bitbang_spi_master_data)); + data->mst = master; + mst.data = data; register_spi_master(&mst); + register_shutdown(bitbang_spi_shutdown, data); /* Only mess with the bus if we're sure nobody else uses it. */ bitbang_spi_request_bus(master); |