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>
diff --git a/linux_spi.c b/linux_spi.c
index 541ca65..4668e7f 100644
--- a/linux_spi.c
+++ b/linux_spi.c
@@ -68,10 +68,8 @@
 
 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 @@
 };
 
 /* 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 @@
 	/* 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 @@
 	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 @@
 	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 @@
 	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 @@
 
 	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