diff options
author | Anastasia Klimchuk <aklm@chromium.org> | 2021-04-19 11:12:01 +1000 |
---|---|---|
committer | Nico Huber <nico.h@gmx.de> | 2021-04-23 13:18:35 +0000 |
commit | 2a703e440061b752b872a2ee532700043f276941 (patch) | |
tree | 2599e3a0ac6ac77da5fc23a7269a64f74013fa0f | |
parent | 9439c76473305fd413e6408a8ad7a02e174c2f52 (diff) | |
download | flashrom-2a703e440061b752b872a2ee532700043f276941.tar.gz flashrom-2a703e440061b752b872a2ee532700043f276941.tar.bz2 flashrom-2a703e440061b752b872a2ee532700043f276941.zip |
linux_spi.c: Drop some unnecessary initialisations and checks
In previous patches 52283, 52284, 52285 there were some unresolved
comments left, resolving [and replying to] all of that here.
TEST=builds and ninja test from 51487
BUG=b:185191942
Change-Id: I27a718b515fc474f63b3e61be58a6f9302527559
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/52492
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Reviewed-by: Nico Huber <nico.h@gmx.de>
-rw-r--r-- | linux_spi.c | 24 |
1 files changed, 7 insertions, 17 deletions
diff --git a/linux_spi.c b/linux_spi.c index 541ca654..4668e7f2 100644 --- a/linux_spi.c +++ b/linux_spi.c @@ -68,10 +68,8 @@ static int linux_spi_write_256(struct flashctx *flash, const uint8_t *buf, unsig static int linux_spi_shutdown(void *data) { - struct linux_spi_data *spi_data = (struct linux_spi_data *) data; - if (spi_data->fd != -1) - close(spi_data->fd); - + struct linux_spi_data *spi_data = data; + close(spi_data->fd); free(spi_data); return 0; } @@ -127,7 +125,8 @@ static struct spi_master spi_master_linux = { }; /* Read max buffer size from sysfs, or use page size as fallback. */ -static size_t get_max_kernel_buf_size() { +static size_t get_max_kernel_buf_size() +{ size_t result = 0; FILE *fp; fp = fopen(BUF_SIZE_FROM_SYSFS, "r"); @@ -174,10 +173,9 @@ int linux_spi_init(void) /* SPI mode 0 (beware this also includes: MSB first, CS active low and others */ const uint8_t mode = SPI_MODE_0; const uint8_t bits = 8; - int fd = -1; + int fd; size_t max_kernel_buf_size; struct linux_spi_data *spi_data; - int ret = 0; p = extract_programmer_param("spispeed"); if (p && strlen(p)) { @@ -214,7 +212,6 @@ int linux_spi_init(void) if (ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed_hz) == -1) { msg_perr("%s: failed to set speed to %"PRIu32"Hz: %s\n", __func__, speed_hz, strerror(errno)); - ret = 1; goto init_err; } msg_pdbg("Using %"PRIu32"kHz clock\n", speed_hz / 1000); @@ -222,14 +219,12 @@ int linux_spi_init(void) if (ioctl(fd, SPI_IOC_WR_MODE, &mode) == -1) { msg_perr("%s: failed to set SPI mode to 0x%02x: %s\n", __func__, mode, strerror(errno)); - ret = 1; goto init_err; } if (ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits) == -1) { msg_perr("%s: failed to set the number of bits per SPI word to %u: %s\n", __func__, bits == 0 ? 8 : bits, strerror(errno)); - ret = 1; goto init_err; } @@ -239,7 +234,6 @@ int linux_spi_init(void) spi_data = calloc(1, sizeof(*spi_data)); if (!spi_data) { msg_perr("Unable to allocated space for SPI master data\n"); - ret = SPI_GENERIC_ERROR; goto init_err; } spi_data->fd = fd; @@ -248,18 +242,14 @@ int linux_spi_init(void) if (register_shutdown(linux_spi_shutdown, spi_data)) { free(spi_data); - ret = 1; goto init_err; } register_spi_master(&spi_master_linux); return 0; init_err: - if (fd != -1) { - close(fd); - fd = -1; - } - return ret; + close(fd); + return 1; } #endif // CONFIG_LINUX_SPI == 1 |