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.
Tested: builds and ninja test from 51487
Change-Id: I27a718b515fc474f63b3e61be58a6f9302527559
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Original-Reviewed-on: https://review.coreboot.org/c/flashrom/+/52492
Original-Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Original-Reviewed-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.coreboot.org/c/flashrom-stable/+/72172
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Nico Huber <nico.h@gmx.de>
diff --git a/linux_spi.c b/linux_spi.c
index fdfec55..033c94a 100644
--- a/linux_spi.c
+++ b/linux_spi.c
@@ -73,7 +73,8 @@
};
/* 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");
@@ -120,10 +121,9 @@
/* 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)) {
@@ -160,7 +160,6 @@
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);
@@ -168,14 +167,12 @@
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;
}
@@ -185,7 +182,6 @@
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;
@@ -194,26 +190,20 @@
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;
}
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;
}