mirror of
https://review.coreboot.org/flashrom.git
synced 2025-04-27 07:02:34 +02:00
spi_master: Use new API to register shutdown function
This allows spi masters to register shutdown function in spi_master struct, which means there is no need to call register_shutdown in init function, since this call is now a part of register_spi_master. As a consequence of using new API, two things are happening here: 1) No resource leakage anymore in case register_shutdown() would fail, 2) Fixed propagation of register_spi_master() return values. Basic testing: when I comment out free(data) in linux_spi_shutdown, test fails with error ../linux_spi.c:235: note: block 0x55a4db276510 allocated here ERROR: linux_spi_init_and_shutdown_test_success leaked 1 block(s) Means, shutdown function is invoked. BUG=b:185191942 TEST= 1) builds and ninja test including CB:56911 2) On ARMv7 device flashrom -p linux_spi -V -> using linux_spi, chip found 3) On x86_64 AMD device flashrom -p internal -V -> this is actually using sb600spi, chip found Change-Id: Ib60300f9ddb295a255d5ef3f8da0e07064207140 Signed-off-by: Anastasia Klimchuk <aklm@chromium.org> Reviewed-on: https://review.coreboot.org/c/flashrom/+/56103 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Nico Huber <nico.h@gmx.de> Reviewed-by: Angel Pons <th3fanbus@gmail.com> Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
This commit is contained in:
parent
9db8e12c16
commit
a69c5196d2
@ -147,6 +147,7 @@ static const struct spi_master spi_master_bitbang = {
|
||||
.read = default_spi_read,
|
||||
.write_256 = default_spi_write_256,
|
||||
.write_aai = default_spi_write_aai,
|
||||
.shutdown = bitbang_spi_shutdown,
|
||||
};
|
||||
|
||||
int register_spi_bitbang_master(const struct bitbang_spi_master *master, void *spi_data)
|
||||
@ -168,7 +169,6 @@ int register_spi_bitbang_master(const struct bitbang_spi_master *master, void *s
|
||||
data->spi_data = spi_data;
|
||||
|
||||
register_spi_master(&mst, data);
|
||||
register_shutdown(bitbang_spi_shutdown, data);
|
||||
|
||||
/* Only mess with the bus if we're sure nobody else uses it. */
|
||||
bitbang_spi_request_bus(master, spi_data);
|
||||
|
@ -181,6 +181,7 @@ static struct spi_master spi_master_buspirate = {
|
||||
.read = default_spi_read,
|
||||
.write_256 = default_spi_write_256,
|
||||
.write_aai = default_spi_write_aai,
|
||||
.shutdown = buspirate_spi_shutdown,
|
||||
};
|
||||
|
||||
static const struct buspirate_speeds spispeeds[] = {
|
||||
@ -698,13 +699,7 @@ static int buspirate_spi_init(void)
|
||||
goto init_err_cleanup_exit;
|
||||
}
|
||||
|
||||
if (register_shutdown(buspirate_spi_shutdown, bp_data) != 0) {
|
||||
ret = 1;
|
||||
goto init_err_cleanup_exit;
|
||||
}
|
||||
register_spi_master(&spi_master_buspirate, bp_data);
|
||||
|
||||
return 0;
|
||||
return register_spi_master(&spi_master_buspirate, bp_data);
|
||||
|
||||
init_err_cleanup_exit:
|
||||
buspirate_spi_shutdown(bp_data);
|
||||
|
@ -417,6 +417,7 @@ static const struct spi_master spi_master_ch341a_spi = {
|
||||
.read = default_spi_read,
|
||||
.write_256 = default_spi_write_256,
|
||||
.write_aai = default_spi_write_aai,
|
||||
.shutdown = ch341a_spi_shutdown,
|
||||
};
|
||||
|
||||
static int ch341a_spi_init(void)
|
||||
@ -505,10 +506,7 @@ static int ch341a_spi_init(void)
|
||||
if ((config_stream(CH341A_STM_I2C_100K) < 0) || (enable_pins(true) < 0))
|
||||
goto dealloc_transfers;
|
||||
|
||||
register_shutdown(ch341a_spi_shutdown, NULL);
|
||||
register_spi_master(&spi_master_ch341a_spi, NULL);
|
||||
|
||||
return 0;
|
||||
return register_spi_master(&spi_master_ch341a_spi, NULL);
|
||||
|
||||
dealloc_transfers:
|
||||
for (i = 0; i < USB_IN_TRANSFERS; i++) {
|
||||
|
@ -1019,6 +1019,7 @@ static struct spi_master spi_master_dediprog = {
|
||||
.read = dediprog_spi_read,
|
||||
.write_256 = dediprog_spi_write_256,
|
||||
.write_aai = dediprog_spi_write_aai,
|
||||
.shutdown = dediprog_shutdown,
|
||||
};
|
||||
|
||||
/*
|
||||
@ -1271,9 +1272,6 @@ static int dediprog_init(void)
|
||||
if (protocol() >= PROTOCOL_V2)
|
||||
spi_master_dediprog.features |= SPI_MASTER_4BA;
|
||||
|
||||
if (register_shutdown(dediprog_shutdown, NULL))
|
||||
goto init_err_cleanup_exit;
|
||||
|
||||
if (register_spi_master(&spi_master_dediprog, NULL) || dediprog_set_leds(LED_NONE))
|
||||
return 1; /* shutdown function does cleanup */
|
||||
|
||||
|
@ -337,6 +337,7 @@ static const struct spi_master spi_master_digilent_spi = {
|
||||
.read = default_spi_read,
|
||||
.write_256 = default_spi_write_256,
|
||||
.write_aai = default_spi_write_aai,
|
||||
.shutdown = digilent_spi_shutdown,
|
||||
};
|
||||
|
||||
static bool default_reset(struct libusb_device_handle *handle)
|
||||
@ -454,10 +455,7 @@ static int digilent_spi_init(void)
|
||||
digilent_data->reset_board = reset_board;
|
||||
digilent_data->handle = handle;
|
||||
|
||||
register_shutdown(digilent_spi_shutdown, digilent_data);
|
||||
register_spi_master(&spi_master_digilent_spi, digilent_data);
|
||||
|
||||
return 0;
|
||||
return register_spi_master(&spi_master_digilent_spi, digilent_data);
|
||||
|
||||
close_handle:
|
||||
libusb_close(handle);
|
||||
|
12
ene_lpc.c
12
ene_lpc.c
@ -512,6 +512,7 @@ static const struct spi_master spi_master_ene = {
|
||||
.read = default_spi_read,
|
||||
.write_256 = default_spi_write_256,
|
||||
.write_aai = default_spi_write_aai,
|
||||
.shutdown = ene_leave_flash_mode,
|
||||
};
|
||||
|
||||
static int check_params(void)
|
||||
@ -570,16 +571,7 @@ static int ene_lpc_init()
|
||||
|
||||
internal_buses_supported |= BUS_LPC;
|
||||
|
||||
if (register_shutdown(ene_leave_flash_mode, ctx_data))
|
||||
goto init_err_cleanup_exit;
|
||||
register_spi_master(&spi_master_ene, ctx_data);
|
||||
msg_pdbg("%s: successfully initialized ene\n", __func__);
|
||||
|
||||
return 0;
|
||||
|
||||
init_err_cleanup_exit:
|
||||
ene_leave_flash_mode(ctx_data);
|
||||
return 1;
|
||||
return register_spi_master(&spi_master_ene, ctx_data);
|
||||
|
||||
init_err_exit:
|
||||
free(ctx_data);
|
||||
|
@ -291,6 +291,7 @@ static const struct spi_master spi_master_ft2232 = {
|
||||
.read = default_spi_read,
|
||||
.write_256 = default_spi_write_256,
|
||||
.write_aai = default_spi_write_aai,
|
||||
.shutdown = ft2232_shutdown,
|
||||
};
|
||||
|
||||
/* Returns 0 upon success, a negative number upon errors. */
|
||||
@ -579,13 +580,7 @@ static int ft2232_spi_init(void)
|
||||
spi_data->pindir = pindir;
|
||||
spi_data->ftdic_context = ftdic;
|
||||
|
||||
if (register_shutdown(ft2232_shutdown, spi_data)) {
|
||||
free(spi_data);
|
||||
goto ftdi_err;
|
||||
}
|
||||
register_spi_master(&spi_master_ft2232, spi_data);
|
||||
|
||||
return 0;
|
||||
return register_spi_master(&spi_master_ft2232, spi_data);
|
||||
|
||||
ftdi_err:
|
||||
if ((f = ftdi_usb_close(&ftdic)) < 0) {
|
||||
|
10
it85spi.c
10
it85spi.c
@ -289,6 +289,7 @@ static const struct spi_master spi_master_it85xx = {
|
||||
.read = default_spi_read,
|
||||
.write_256 = default_spi_write_256,
|
||||
.write_aai = default_spi_write_aai,
|
||||
.shutdown = it85xx_shutdown,
|
||||
};
|
||||
|
||||
int it85xx_spi_init(struct superio s)
|
||||
@ -353,20 +354,13 @@ int it85xx_spi_init(struct superio s)
|
||||
data->ce_high = ((unsigned char *)base) + 0xE00; /* 0xFFFFFE00 */
|
||||
data->ce_low = ((unsigned char *)base) + 0xD00; /* 0xFFFFFD00 */
|
||||
|
||||
if (register_shutdown(it85xx_shutdown, data)) {
|
||||
free(data);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* FIXME: Really leave FWH enabled? We can't use this region
|
||||
* anymore since accessing it would mess up IT85 communication.
|
||||
* If we decide to disable FWH for this region, we should print
|
||||
* a debug message about it.
|
||||
*/
|
||||
/* Set this as SPI controller. */
|
||||
register_spi_master(&spi_master_it85xx, data);
|
||||
|
||||
return 0;
|
||||
return register_spi_master(&spi_master_it85xx, data);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -304,6 +304,7 @@ static const struct spi_master spi_master_it87xx = {
|
||||
.read = it8716f_spi_chip_read,
|
||||
.write_256 = it8716f_spi_chip_write_256,
|
||||
.write_aai = spi_chip_write_1,
|
||||
.shutdown = it8716f_shutdown,
|
||||
};
|
||||
|
||||
static uint16_t it87spi_probe(uint16_t port)
|
||||
@ -419,13 +420,10 @@ static uint16_t it87spi_probe(uint16_t port)
|
||||
data->flashport = flashport;
|
||||
data->fast_spi = 1;
|
||||
|
||||
register_shutdown(it8716f_shutdown, data);
|
||||
|
||||
if (internal_buses_supported & BUS_SPI)
|
||||
msg_pdbg("Overriding chipset SPI with IT87 SPI.\n");
|
||||
/* FIXME: Add the SPI bus or replace the other buses with it? */
|
||||
register_spi_master(&spi_master_it87xx, data);
|
||||
return 0;
|
||||
return register_spi_master(&spi_master_it87xx, data);
|
||||
}
|
||||
|
||||
int init_superio_ite(void)
|
||||
|
@ -179,6 +179,7 @@ static const struct spi_master spi_master_jlink_spi = {
|
||||
.write_256 = default_spi_write_256,
|
||||
.write_aai = default_spi_write_aai,
|
||||
.features = SPI_MASTER_4BA,
|
||||
.shutdown = jlink_spi_shutdown,
|
||||
};
|
||||
|
||||
static int jlink_spi_init(void)
|
||||
@ -468,11 +469,7 @@ static int jlink_spi_init(void)
|
||||
if (!deassert_cs(jlink_data))
|
||||
goto init_err;
|
||||
|
||||
if (register_shutdown(jlink_spi_shutdown, jlink_data))
|
||||
goto init_err;
|
||||
register_spi_master(&spi_master_jlink_spi, jlink_data);
|
||||
|
||||
return 0;
|
||||
return register_spi_master(&spi_master_jlink_spi, jlink_data);
|
||||
|
||||
init_err:
|
||||
if (jaylink_devh)
|
||||
|
@ -122,6 +122,7 @@ static const struct spi_master spi_master_linux = {
|
||||
.read = linux_spi_read,
|
||||
.write_256 = linux_spi_write_256,
|
||||
.write_aai = default_spi_write_aai,
|
||||
.shutdown = linux_spi_shutdown,
|
||||
};
|
||||
|
||||
/* Read max buffer size from sysfs, or use page size as fallback. */
|
||||
@ -239,12 +240,7 @@ static int linux_spi_init(void)
|
||||
spi_data->fd = fd;
|
||||
spi_data->max_kernel_buf_size = max_kernel_buf_size;
|
||||
|
||||
if (register_shutdown(linux_spi_shutdown, spi_data)) {
|
||||
free(spi_data);
|
||||
goto init_err;
|
||||
}
|
||||
register_spi_master(&spi_master_linux, spi_data);
|
||||
return 0;
|
||||
return register_spi_master(&spi_master_linux, spi_data);
|
||||
|
||||
init_err:
|
||||
close(fd);
|
||||
|
@ -434,6 +434,7 @@ static const struct spi_master spi_master_i2c_lspcon = {
|
||||
.read = lspcon_i2c_spi_read,
|
||||
.write_256 = lspcon_i2c_spi_write_256,
|
||||
.write_aai = lspcon_i2c_spi_write_aai,
|
||||
.shutdown = lspcon_i2c_spi_shutdown,
|
||||
};
|
||||
|
||||
static int lspcon_i2c_spi_init(void)
|
||||
@ -458,10 +459,7 @@ static int lspcon_i2c_spi_init(void)
|
||||
|
||||
data->fd = fd;
|
||||
|
||||
ret |= register_shutdown(lspcon_i2c_spi_shutdown, data);
|
||||
ret |= register_spi_master(&spi_master_i2c_lspcon, data);
|
||||
|
||||
return ret;
|
||||
return register_spi_master(&spi_master_i2c_lspcon, data);
|
||||
}
|
||||
|
||||
const struct programmer_entry programmer_lspcon_i2c_spi = {
|
||||
|
@ -405,6 +405,7 @@ static const struct spi_master spi_master_mec1308 = {
|
||||
.read = default_spi_read,
|
||||
.write_256 = default_spi_write_256,
|
||||
.write_aai = default_spi_write_aai,
|
||||
.shutdown = mec1308_shutdown,
|
||||
};
|
||||
|
||||
static int check_params(void)
|
||||
@ -507,12 +508,7 @@ static int mec1308_init(void)
|
||||
|
||||
internal_buses_supported |= BUS_LPC; /* for LPC <--> SPI bridging */
|
||||
|
||||
if (register_shutdown(mec1308_shutdown, ctx_data))
|
||||
goto init_err_cleanup_exit;
|
||||
register_spi_master(&spi_master_mec1308, ctx_data);
|
||||
msg_pdbg("%s(): successfully initialized mec1308\n", __func__);
|
||||
|
||||
return 0;
|
||||
return register_spi_master(&spi_master_mec1308, ctx_data);
|
||||
|
||||
init_err_cleanup_exit:
|
||||
mec1308_shutdown(ctx_data);
|
||||
|
@ -147,6 +147,7 @@ static const struct spi_master spi_master_mstarddc = {
|
||||
.read = default_spi_read,
|
||||
.write_256 = default_spi_write_256,
|
||||
.write_aai = default_spi_write_aai,
|
||||
.shutdown = mstarddc_spi_shutdown,
|
||||
};
|
||||
|
||||
/* Returns 0 upon success, a negative number upon errors. */
|
||||
@ -240,9 +241,6 @@ static int mstarddc_spi_init(void)
|
||||
mstarddc_data->addr = mstarddc_addr;
|
||||
mstarddc_data->doreset = mstarddc_doreset;
|
||||
|
||||
// Register shutdown function
|
||||
register_shutdown(mstarddc_spi_shutdown, mstarddc_data);
|
||||
|
||||
// Register programmer
|
||||
register_spi_master(&spi_master_mstarddc, mstarddc_data);
|
||||
out:
|
||||
|
10
ni845x_spi.c
10
ni845x_spi.c
@ -536,6 +536,7 @@ static const struct spi_master spi_programmer_ni845x = {
|
||||
.read = default_spi_read,
|
||||
.write_256 = default_spi_write_256,
|
||||
.write_aai = default_spi_write_aai,
|
||||
.shutdown = ni845x_spi_shutdown,
|
||||
};
|
||||
|
||||
static int ni845x_spi_init(void)
|
||||
@ -625,14 +626,7 @@ static int ni845x_spi_init(void)
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (register_shutdown(ni845x_spi_shutdown, NULL)) {
|
||||
ni845x_spi_shutdown(NULL);
|
||||
return 1;
|
||||
}
|
||||
|
||||
register_spi_master(&spi_programmer_ni845x, NULL);
|
||||
|
||||
return 0;
|
||||
return register_spi_master(&spi_programmer_ni845x, NULL);
|
||||
}
|
||||
|
||||
const struct programmer_entry programmer_ni845x_spi = {
|
||||
|
@ -386,6 +386,7 @@ static const struct spi_master spi_master_pickit2 = {
|
||||
.read = default_spi_read,
|
||||
.write_256 = default_spi_write_256,
|
||||
.write_aai = default_spi_write_aai,
|
||||
.shutdown = pickit2_shutdown,
|
||||
};
|
||||
|
||||
static int pickit2_spi_init(void)
|
||||
@ -498,11 +499,7 @@ static int pickit2_spi_init(void)
|
||||
goto init_err_cleanup_exit;
|
||||
}
|
||||
|
||||
if (register_shutdown(pickit2_shutdown, pickit2_data))
|
||||
goto init_err_cleanup_exit;
|
||||
register_spi_master(&spi_master_pickit2, pickit2_data);
|
||||
|
||||
return 0;
|
||||
return register_spi_master(&spi_master_pickit2, pickit2_data);
|
||||
|
||||
init_err_cleanup_exit:
|
||||
pickit2_shutdown(pickit2_data);
|
||||
|
@ -440,6 +440,7 @@ static const struct spi_master spi_master_i2c_realtek_mst = {
|
||||
.read = realtek_mst_i2c_spi_read,
|
||||
.write_256 = realtek_mst_i2c_spi_write_256,
|
||||
.write_aai = realtek_mst_i2c_spi_write_aai,
|
||||
.shutdown = realtek_mst_i2c_spi_shutdown,
|
||||
};
|
||||
|
||||
static int get_params(int *reset, int *enter_isp)
|
||||
@ -512,10 +513,7 @@ static int realtek_mst_i2c_spi_init(void)
|
||||
|
||||
data->fd = fd;
|
||||
data->reset = reset;
|
||||
ret |= register_shutdown(realtek_mst_i2c_spi_shutdown, data);
|
||||
ret |= register_spi_master(&spi_master_i2c_realtek_mst, data);
|
||||
|
||||
return ret;
|
||||
return register_spi_master(&spi_master_i2c_realtek_mst, data);
|
||||
}
|
||||
|
||||
const struct programmer_entry programmer_realtek_mst_i2c_spi = {
|
||||
|
@ -589,6 +589,7 @@ static const struct spi_master spi_master_sb600 = {
|
||||
.read = default_spi_read,
|
||||
.write_256 = default_spi_write_256,
|
||||
.write_aai = default_spi_write_aai,
|
||||
.shutdown = sb600spi_shutdown,
|
||||
};
|
||||
|
||||
static const struct spi_master spi_master_yangtze = {
|
||||
@ -599,6 +600,7 @@ static const struct spi_master spi_master_yangtze = {
|
||||
.read = default_spi_read,
|
||||
.write_256 = default_spi_write_256,
|
||||
.write_aai = default_spi_write_aai,
|
||||
.shutdown = sb600spi_shutdown,
|
||||
};
|
||||
|
||||
static const struct spi_master spi_master_promontory = {
|
||||
@ -609,6 +611,7 @@ static const struct spi_master spi_master_promontory = {
|
||||
.read = promontory_read_memmapped,
|
||||
.write_256 = default_spi_write_256,
|
||||
.write_aai = default_spi_write_aai,
|
||||
.shutdown = sb600spi_shutdown,
|
||||
};
|
||||
|
||||
int sb600_probe_spi(struct pci_dev *dev)
|
||||
@ -786,8 +789,6 @@ int sb600_probe_spi(struct pci_dev *dev)
|
||||
data->flash = NULL;
|
||||
data->spibar = sb600_spibar;
|
||||
|
||||
register_shutdown(sb600spi_shutdown, data);
|
||||
|
||||
/* Starting with Yangtze the SPI controller got a different interface with a much bigger buffer. */
|
||||
if (amd_gen < CHIPSET_YANGTZE)
|
||||
register_spi_master(&spi_master_sb600, data);
|
||||
|
@ -467,6 +467,7 @@ static const struct spi_master spi_programmer_stlinkv3 = {
|
||||
.read = default_spi_read,
|
||||
.write_256 = default_spi_write_256,
|
||||
.write_aai = default_spi_write_aai,
|
||||
.shutdown = stlinkv3_spi_shutdown,
|
||||
};
|
||||
|
||||
static int stlinkv3_spi_init(void)
|
||||
@ -531,17 +532,7 @@ static int stlinkv3_spi_init(void)
|
||||
stlinkv3_data->usb_ctx = usb_ctx;
|
||||
stlinkv3_data->handle = stlinkv3_handle;
|
||||
|
||||
if (register_shutdown(stlinkv3_spi_shutdown, stlinkv3_data))
|
||||
goto init_err_cleanup_exit;
|
||||
|
||||
if (register_spi_master(&spi_programmer_stlinkv3, stlinkv3_data))
|
||||
return 1; /* shutdown function does cleanup */
|
||||
|
||||
return 0;
|
||||
|
||||
init_err_cleanup_exit:
|
||||
stlinkv3_spi_shutdown(stlinkv3_data);
|
||||
return 1;
|
||||
return register_spi_master(&spi_programmer_stlinkv3, stlinkv3_data);
|
||||
|
||||
init_err_exit:
|
||||
if (stlinkv3_handle)
|
||||
|
@ -174,6 +174,7 @@ static const struct spi_master spi_master_usbblaster = {
|
||||
.read = default_spi_read,
|
||||
.write_256 = default_spi_write_256,
|
||||
.write_aai = default_spi_write_aai,
|
||||
.shutdown = usbblaster_shutdown,
|
||||
};
|
||||
|
||||
/* Returns 0 upon success, a negative number upon errors. */
|
||||
@ -224,12 +225,7 @@ static int usbblaster_spi_init(void)
|
||||
}
|
||||
usbblaster_data->ftdic = ftdic;
|
||||
|
||||
if (register_shutdown(usbblaster_shutdown, usbblaster_data)) {
|
||||
free(usbblaster_data);
|
||||
return -1;
|
||||
}
|
||||
register_spi_master(&spi_master_usbblaster, usbblaster_data);
|
||||
return 0;
|
||||
return register_spi_master(&spi_master_usbblaster, usbblaster_data);
|
||||
}
|
||||
|
||||
const struct programmer_entry programmer_usbblaster_spi = {
|
||||
|
@ -191,6 +191,7 @@ static const struct spi_master spi_master_wbsio = {
|
||||
.read = wbsio_spi_read,
|
||||
.write_256 = spi_chip_write_1,
|
||||
.write_aai = spi_chip_write_1,
|
||||
.shutdown = wbsio_spi_shutdown,
|
||||
};
|
||||
|
||||
int wbsio_check_for_spi(void)
|
||||
@ -214,10 +215,7 @@ int wbsio_check_for_spi(void)
|
||||
}
|
||||
data->spibase = wbsio_spibase;
|
||||
|
||||
register_shutdown(wbsio_spi_shutdown, data);
|
||||
register_spi_master(&spi_master_wbsio, data);
|
||||
|
||||
return 0;
|
||||
return register_spi_master(&spi_master_wbsio, data);
|
||||
}
|
||||
|
||||
#endif /* defined(__i386__) || defined(__x86_64__) */
|
||||
|
Loading…
x
Reference in New Issue
Block a user