From e1f30bbce7a603d518ecec9d7e6885719f396719 Mon Sep 17 00:00:00 2001 From: Edward O'Callaghan Date: Tue, 20 Dec 2022 12:33:13 +1100 Subject: tree/: Drop default_spi_probe_opcode for NULL case A NULL func pointer is necessary and sufficient for the condition `NULL func pointer => true' as to not need this boilerplate as it implies default behaviour of a supported opcode within the `check_block_eraser()` match supported loop. Ran; ``` $ find . -name '*.[c,h]' -exec sed -i '/.probe_opcode = default_spi_probe_opcode,/d' '{}' \; ``` Change-Id: Id502c5d2596ad1db52faf05723083620e4c52c12 Signed-off-by: Edward O'Callaghan Reviewed-on: https://review.coreboot.org/c/flashrom/+/70264 Tested-by: build bot (Jenkins) Reviewed-by: Thomas Heijligen Reviewed-by: Anastasia Klimchuk --- asm106x.c | 1 - bitbang_spi.c | 1 - buspirate_spi.c | 1 - ch341a_spi.c | 1 - ch347_spi.c | 1 - dediprog.c | 1 - digilent_spi.c | 1 - dirtyjtag_spi.c | 1 - flashrom.c | 2 +- ft2232_spi.c | 1 - include/chipdrivers.h | 1 + include/programmer.h | 3 +-- it87spi.c | 1 - jlink_spi.c | 1 - linux_spi.c | 1 - mediatek_i2c_spi.c | 1 - mstarddc_spi.c | 1 - ni845x_spi.c | 1 - parade_lspcon.c | 1 - pickit2_spi.c | 1 - raiden_debug_spi.c | 1 - realtek_mst_i2c_spi.c | 1 - sb600spi.c | 3 --- serprog.c | 1 - spi.c | 9 +++++---- spi25_statusreg.c | 4 ++-- stlinkv3_spi.c | 1 - usbblaster_spi.c | 1 - wbsio_spi.c | 1 - 29 files changed, 10 insertions(+), 35 deletions(-) diff --git a/asm106x.c b/asm106x.c index 78c0b74c..0c9cf111 100644 --- a/asm106x.c +++ b/asm106x.c @@ -125,7 +125,6 @@ static const struct spi_master asm106x_spi_master = { .shutdown = asm106x_shutdown, .read = default_spi_read, .write_256 = default_spi_write_256, - .probe_opcode = default_spi_probe_opcode, }; static int asm106x_init(const struct programmer_cfg *cfg) diff --git a/bitbang_spi.c b/bitbang_spi.c index 6488650c..dde5dbc4 100644 --- a/bitbang_spi.c +++ b/bitbang_spi.c @@ -146,7 +146,6 @@ static const struct spi_master spi_master_bitbang = { .read = default_spi_read, .write_256 = default_spi_write_256, .shutdown = bitbang_spi_shutdown, - .probe_opcode = default_spi_probe_opcode, }; int register_spi_bitbang_master(const struct bitbang_spi_master *master, void *spi_data) diff --git a/buspirate_spi.c b/buspirate_spi.c index 192d2743..d3114c41 100644 --- a/buspirate_spi.c +++ b/buspirate_spi.c @@ -181,7 +181,6 @@ static struct spi_master spi_master_buspirate = { .read = default_spi_read, .write_256 = default_spi_write_256, .shutdown = buspirate_spi_shutdown, - .probe_opcode = default_spi_probe_opcode, }; static const struct buspirate_speeds spispeeds[] = { diff --git a/ch341a_spi.c b/ch341a_spi.c index b9be18e5..a66503d9 100644 --- a/ch341a_spi.c +++ b/ch341a_spi.c @@ -416,7 +416,6 @@ static const struct spi_master spi_master_ch341a_spi = { .read = default_spi_read, .write_256 = default_spi_write_256, .shutdown = ch341a_spi_shutdown, - .probe_opcode = default_spi_probe_opcode, .delay = ch341a_spi_delay, }; diff --git a/ch347_spi.c b/ch347_spi.c index e828f008..570e25be 100644 --- a/ch347_spi.c +++ b/ch347_spi.c @@ -257,7 +257,6 @@ static const struct spi_master spi_master_ch347_spi = { .write_256 = default_spi_write_256, .write_aai = default_spi_write_aai, .shutdown = ch347_spi_shutdown, - .probe_opcode = default_spi_probe_opcode, }; /* Largely copied from ch341a_spi.c */ diff --git a/dediprog.c b/dediprog.c index 60ce6e6e..734fcfa1 100644 --- a/dediprog.c +++ b/dediprog.c @@ -1038,7 +1038,6 @@ static struct spi_master spi_master_dediprog = { .write_256 = dediprog_spi_write_256, .write_aai = dediprog_spi_write_aai, .shutdown = dediprog_shutdown, - .probe_opcode = default_spi_probe_opcode, }; /* diff --git a/digilent_spi.c b/digilent_spi.c index 5fa60b92..ef0d23cf 100644 --- a/digilent_spi.c +++ b/digilent_spi.c @@ -336,7 +336,6 @@ static const struct spi_master spi_master_digilent_spi = { .read = default_spi_read, .write_256 = default_spi_write_256, .shutdown = digilent_spi_shutdown, - .probe_opcode = default_spi_probe_opcode, }; static bool default_reset(struct libusb_device_handle *handle) diff --git a/dirtyjtag_spi.c b/dirtyjtag_spi.c index 9f0e43bf..19764f62 100644 --- a/dirtyjtag_spi.c +++ b/dirtyjtag_spi.c @@ -197,7 +197,6 @@ static const struct spi_master spi_master_dirtyjtag_spi = { .write_256 = default_spi_write_256, .write_aai = default_spi_write_aai, .shutdown = dirtyjtag_spi_shutdown, - .probe_opcode = default_spi_probe_opcode, }; static int dirtyjtag_spi_init(const struct programmer_cfg *cfg) diff --git a/flashrom.c b/flashrom.c index 62e57576..3cf67f1d 100644 --- a/flashrom.c +++ b/flashrom.c @@ -470,7 +470,7 @@ int check_block_eraser(const struct flashctx *flash, int k, int log) if (flash->mst->buses_supported & BUS_SPI) { const uint8_t *opcode = spi_get_opcode_from_erasefn(eraser.block_erase); for (int i = 0; opcode[i]; i++) { - if (!flash->mst->spi.probe_opcode(flash, opcode[i])) { + if (!spi_probe_opcode(flash, opcode[i])) { if (log) msg_cdbg("block erase function and layout found " "but SPI master doesn't support the function. "); diff --git a/ft2232_spi.c b/ft2232_spi.c index 16bcfe31..7d7283bc 100644 --- a/ft2232_spi.c +++ b/ft2232_spi.c @@ -299,7 +299,6 @@ static const struct spi_master spi_master_ft2232 = { .read = default_spi_read, .write_256 = default_spi_write_256, .shutdown = ft2232_shutdown, - .probe_opcode = default_spi_probe_opcode, }; /* Returns 0 upon success, a negative number upon errors. */ diff --git a/include/chipdrivers.h b/include/chipdrivers.h index 71b87954..c485aafa 100644 --- a/include/chipdrivers.h +++ b/include/chipdrivers.h @@ -26,6 +26,7 @@ int spi_aai_write(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len); int spi_chip_write_256(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len); int spi_chip_read(struct flashctx *flash, uint8_t *buf, unsigned int start, int unsigned len); +bool spi_probe_opcode(const struct flashctx *flash, uint8_t opcode); /* spi25.c */ int probe_spi_rdid(struct flashctx *flash); diff --git a/include/programmer.h b/include/programmer.h index f6bc8ce6..d8d8b4a2 100644 --- a/include/programmer.h +++ b/include/programmer.h @@ -312,7 +312,7 @@ struct spi_master { int (*write_256)(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len); int (*write_aai)(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len); int (*shutdown)(void *data); - bool (*probe_opcode)(const struct flashctx *flash, uint8_t opcode); + bool (*probe_opcode)(const struct flashctx *flash, uint8_t opcode); /* NULL func implies true. */ void (*delay) (const struct flashctx *flash, unsigned int usecs); void (*get_region)(const struct flashctx *flash, unsigned int addr, struct flash_region *region); void *data; @@ -321,7 +321,6 @@ struct spi_master { int default_spi_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len); int default_spi_write_256(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len); int default_spi_write_aai(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len); -bool default_spi_probe_opcode(const struct flashctx *flash, uint8_t opcode); int register_spi_master(const struct spi_master *mst, void *data); /* The following enum is needed by ich_descriptor_tool and ich* code as well as in chipset_enable.c. */ diff --git a/it87spi.c b/it87spi.c index b2da8751..9c64659f 100644 --- a/it87spi.c +++ b/it87spi.c @@ -320,7 +320,6 @@ static const struct spi_master spi_master_it87xx = { .write_256 = it8716f_spi_chip_write_256, .write_aai = spi_chip_write_1, .shutdown = it8716f_shutdown, - .probe_opcode = default_spi_probe_opcode, }; static uint16_t it87spi_probe(const struct programmer_cfg *cfg, uint16_t port) diff --git a/jlink_spi.c b/jlink_spi.c index 7743c40b..af61fb59 100644 --- a/jlink_spi.c +++ b/jlink_spi.c @@ -188,7 +188,6 @@ static const struct spi_master spi_master_jlink_spi = { .write_256 = default_spi_write_256, .features = SPI_MASTER_4BA, .shutdown = jlink_spi_shutdown, - .probe_opcode = default_spi_probe_opcode, }; static int jlink_spi_init(const struct programmer_cfg *cfg) diff --git a/linux_spi.c b/linux_spi.c index d849fe4b..ceca05f9 100644 --- a/linux_spi.c +++ b/linux_spi.c @@ -119,7 +119,6 @@ static const struct spi_master spi_master_linux = { .read = linux_spi_read, .write_256 = linux_spi_write_256, .shutdown = linux_spi_shutdown, - .probe_opcode = default_spi_probe_opcode, }; /* Read max buffer size from sysfs, or use page size as fallback. */ diff --git a/mediatek_i2c_spi.c b/mediatek_i2c_spi.c index e9c3c8c8..d28e4781 100644 --- a/mediatek_i2c_spi.c +++ b/mediatek_i2c_spi.c @@ -459,7 +459,6 @@ static const struct spi_master spi_master_i2c_mediatek = { .read = default_spi_read, .write_256 = default_spi_write_256, .shutdown = mediatek_shutdown, - .probe_opcode = default_spi_probe_opcode, }; static int get_params(const struct programmer_cfg *cfg, bool *allow_brick) diff --git a/mstarddc_spi.c b/mstarddc_spi.c index 1172cb20..44ebd054 100644 --- a/mstarddc_spi.c +++ b/mstarddc_spi.c @@ -145,7 +145,6 @@ static const struct spi_master spi_master_mstarddc = { .read = default_spi_read, .write_256 = default_spi_write_256, .shutdown = mstarddc_spi_shutdown, - .probe_opcode = default_spi_probe_opcode, }; /* Returns 0 upon success, a negative number upon errors. */ diff --git a/ni845x_spi.c b/ni845x_spi.c index dec6f6f3..253025f0 100644 --- a/ni845x_spi.c +++ b/ni845x_spi.c @@ -535,7 +535,6 @@ static const struct spi_master spi_programmer_ni845x = { .read = default_spi_read, .write_256 = default_spi_write_256, .shutdown = ni845x_spi_shutdown, - .probe_opcode = default_spi_probe_opcode, }; static int ni845x_spi_init(const struct programmer_cfg *cfg) diff --git a/parade_lspcon.c b/parade_lspcon.c index 8b927893..dfcf6596 100644 --- a/parade_lspcon.c +++ b/parade_lspcon.c @@ -436,7 +436,6 @@ static const struct spi_master spi_master_parade_lspcon = { .write_256 = parade_lspcon_write_256, .write_aai = parade_lspcon_write_aai, .shutdown = parade_lspcon_shutdown, - .probe_opcode = default_spi_probe_opcode, }; static int get_params(const struct programmer_cfg *cfg, bool *allow_brick) diff --git a/pickit2_spi.c b/pickit2_spi.c index 56894d9a..a072a205 100644 --- a/pickit2_spi.c +++ b/pickit2_spi.c @@ -383,7 +383,6 @@ static const struct spi_master spi_master_pickit2 = { .read = default_spi_read, .write_256 = default_spi_write_256, .shutdown = pickit2_shutdown, - .probe_opcode = default_spi_probe_opcode, }; static int pickit2_spi_init(const struct programmer_cfg *cfg) diff --git a/raiden_debug_spi.c b/raiden_debug_spi.c index 5111ae98..c5642ff4 100644 --- a/raiden_debug_spi.c +++ b/raiden_debug_spi.c @@ -1323,7 +1323,6 @@ static const struct spi_master spi_master_raiden_debug = { .read = default_spi_read, .write_256 = default_spi_write_256, .shutdown = raiden_debug_spi_shutdown, - .probe_opcode = default_spi_probe_opcode, }; static int match_endpoint(struct libusb_endpoint_descriptor const *descriptor, diff --git a/realtek_mst_i2c_spi.c b/realtek_mst_i2c_spi.c index ee6390c4..57677ec6 100644 --- a/realtek_mst_i2c_spi.c +++ b/realtek_mst_i2c_spi.c @@ -440,7 +440,6 @@ static const struct spi_master spi_master_i2c_realtek_mst = { .write_256 = realtek_mst_i2c_spi_write_256, .write_aai = realtek_mst_i2c_spi_write_aai, .shutdown = realtek_mst_i2c_spi_shutdown, - .probe_opcode = default_spi_probe_opcode, }; static int get_params(const struct programmer_cfg *cfg, bool *reset, bool *enter_isp, bool *allow_brick) diff --git a/sb600spi.c b/sb600spi.c index 2e6c2eca..df7caedb 100644 --- a/sb600spi.c +++ b/sb600spi.c @@ -604,7 +604,6 @@ static const struct spi_master spi_master_sb600 = { .read = default_spi_read, .write_256 = default_spi_write_256, .shutdown = sb600spi_shutdown, - .probe_opcode = default_spi_probe_opcode, }; static const struct spi_master spi_master_yangtze = { @@ -616,7 +615,6 @@ static const struct spi_master spi_master_yangtze = { .read = default_spi_read, .write_256 = default_spi_write_256, .shutdown = sb600spi_shutdown, - .probe_opcode = default_spi_probe_opcode, }; static const struct spi_master spi_master_promontory = { @@ -628,7 +626,6 @@ static const struct spi_master spi_master_promontory = { .read = promontory_read_memmapped, .write_256 = default_spi_write_256, .shutdown = sb600spi_shutdown, - .probe_opcode = default_spi_probe_opcode, }; int sb600_probe_spi(const struct programmer_cfg *cfg, struct pci_dev *dev) diff --git a/serprog.c b/serprog.c index 4d93e075..b51f0cfe 100644 --- a/serprog.c +++ b/serprog.c @@ -463,7 +463,6 @@ static struct spi_master spi_master_serprog = { .command = serprog_spi_send_command, .read = default_spi_read, .write_256 = default_spi_write_256, - .probe_opcode = default_spi_probe_opcode, .delay = serprog_delay, }; diff --git a/spi.c b/spi.c index 3b3f6229..3e81da2a 100644 --- a/spi.c +++ b/spi.c @@ -139,9 +139,11 @@ int spi_aai_write(struct flashctx *flash, const uint8_t *buf, unsigned int start return default_spi_write_aai(flash, buf, start, len); } -bool default_spi_probe_opcode(const struct flashctx *flash, uint8_t opcode) +bool spi_probe_opcode(const struct flashctx *flash, uint8_t opcode) { - return true; + if (!flash->mst->spi.probe_opcode) + return true; /* no probe_opcode implies default of supported. */ + return flash->mst->spi.probe_opcode(flash, opcode); } int register_spi_master(const struct spi_master *mst, void *data) @@ -155,8 +157,7 @@ int register_spi_master(const struct spi_master *mst, void *data) } } - if (!mst->write_256 || !mst->read || !mst->probe_opcode || - (!mst->command && !mst->multicommand)) { + if (!mst->write_256 || !mst->read || (!mst->command && !mst->multicommand)) { msg_perr("%s called with incomplete master definition. " "Please report a bug at flashrom@flashrom.org\n", __func__); diff --git a/spi25_statusreg.c b/spi25_statusreg.c index ec2c101c..d452416c 100644 --- a/spi25_statusreg.c +++ b/spi25_statusreg.c @@ -132,7 +132,7 @@ int spi_write_register(const struct flashctx *flash, enum flash_reg reg, uint8_t return 1; } - if (!flash->mst->spi.probe_opcode(flash, write_cmd[0])) { + if (!spi_probe_opcode(flash, write_cmd[0])) { msg_pdbg("%s: write to register %d not supported by programmer, ignoring.\n", __func__, reg); return SPI_INVALID_OPCODE; } @@ -246,7 +246,7 @@ int spi_read_register(const struct flashctx *flash, enum flash_reg reg, uint8_t return 1; } - if (!flash->mst->spi.probe_opcode(flash, read_cmd)) { + if (!spi_probe_opcode(flash, read_cmd)) { msg_pdbg("%s: read from register %d not supported by programmer.\n", __func__, reg); return SPI_INVALID_OPCODE; } diff --git a/stlinkv3_spi.c b/stlinkv3_spi.c index 726cdcfd..f9046df0 100644 --- a/stlinkv3_spi.c +++ b/stlinkv3_spi.c @@ -469,7 +469,6 @@ static const struct spi_master spi_programmer_stlinkv3 = { .read = default_spi_read, .write_256 = default_spi_write_256, .shutdown = stlinkv3_spi_shutdown, - .probe_opcode = default_spi_probe_opcode, }; static int stlinkv3_spi_init(const struct programmer_cfg *cfg) diff --git a/usbblaster_spi.c b/usbblaster_spi.c index 958d4ea5..43acaad8 100644 --- a/usbblaster_spi.c +++ b/usbblaster_spi.c @@ -171,7 +171,6 @@ static const struct spi_master spi_master_usbblaster = { .read = default_spi_read, .write_256 = default_spi_write_256, .shutdown = usbblaster_shutdown, - .probe_opcode = default_spi_probe_opcode, }; /* Returns 0 upon success, a negative number upon errors. */ diff --git a/wbsio_spi.c b/wbsio_spi.c index ee79ef2a..febe6ed2 100644 --- a/wbsio_spi.c +++ b/wbsio_spi.c @@ -192,7 +192,6 @@ static const struct spi_master spi_master_wbsio = { .write_256 = spi_chip_write_1, .write_aai = spi_chip_write_1, .shutdown = wbsio_spi_shutdown, - .probe_opcode = default_spi_probe_opcode, }; int wbsio_check_for_spi(void) -- cgit v1.2.3