mirror of
https://review.coreboot.org/flashrom.git
synced 2025-04-27 23:22:37 +02:00
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>
This commit is contained in:
parent
9439c76473
commit
2a703e4400
24
linux_spi.c
24
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)
|
static int linux_spi_shutdown(void *data)
|
||||||
{
|
{
|
||||||
struct linux_spi_data *spi_data = (struct linux_spi_data *) data;
|
struct linux_spi_data *spi_data = data;
|
||||||
if (spi_data->fd != -1)
|
close(spi_data->fd);
|
||||||
close(spi_data->fd);
|
|
||||||
|
|
||||||
free(spi_data);
|
free(spi_data);
|
||||||
return 0;
|
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. */
|
/* 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;
|
size_t result = 0;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
fp = fopen(BUF_SIZE_FROM_SYSFS, "r");
|
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 */
|
/* SPI mode 0 (beware this also includes: MSB first, CS active low and others */
|
||||||
const uint8_t mode = SPI_MODE_0;
|
const uint8_t mode = SPI_MODE_0;
|
||||||
const uint8_t bits = 8;
|
const uint8_t bits = 8;
|
||||||
int fd = -1;
|
int fd;
|
||||||
size_t max_kernel_buf_size;
|
size_t max_kernel_buf_size;
|
||||||
struct linux_spi_data *spi_data;
|
struct linux_spi_data *spi_data;
|
||||||
int ret = 0;
|
|
||||||
|
|
||||||
p = extract_programmer_param("spispeed");
|
p = extract_programmer_param("spispeed");
|
||||||
if (p && strlen(p)) {
|
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) {
|
if (ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed_hz) == -1) {
|
||||||
msg_perr("%s: failed to set speed to %"PRIu32"Hz: %s\n",
|
msg_perr("%s: failed to set speed to %"PRIu32"Hz: %s\n",
|
||||||
__func__, speed_hz, strerror(errno));
|
__func__, speed_hz, strerror(errno));
|
||||||
ret = 1;
|
|
||||||
goto init_err;
|
goto init_err;
|
||||||
}
|
}
|
||||||
msg_pdbg("Using %"PRIu32"kHz clock\n", speed_hz / 1000);
|
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) {
|
if (ioctl(fd, SPI_IOC_WR_MODE, &mode) == -1) {
|
||||||
msg_perr("%s: failed to set SPI mode to 0x%02x: %s\n",
|
msg_perr("%s: failed to set SPI mode to 0x%02x: %s\n",
|
||||||
__func__, mode, strerror(errno));
|
__func__, mode, strerror(errno));
|
||||||
ret = 1;
|
|
||||||
goto init_err;
|
goto init_err;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits) == -1) {
|
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",
|
msg_perr("%s: failed to set the number of bits per SPI word to %u: %s\n",
|
||||||
__func__, bits == 0 ? 8 : bits, strerror(errno));
|
__func__, bits == 0 ? 8 : bits, strerror(errno));
|
||||||
ret = 1;
|
|
||||||
goto init_err;
|
goto init_err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -239,7 +234,6 @@ int linux_spi_init(void)
|
|||||||
spi_data = calloc(1, sizeof(*spi_data));
|
spi_data = calloc(1, sizeof(*spi_data));
|
||||||
if (!spi_data) {
|
if (!spi_data) {
|
||||||
msg_perr("Unable to allocated space for SPI master data\n");
|
msg_perr("Unable to allocated space for SPI master data\n");
|
||||||
ret = SPI_GENERIC_ERROR;
|
|
||||||
goto init_err;
|
goto init_err;
|
||||||
}
|
}
|
||||||
spi_data->fd = fd;
|
spi_data->fd = fd;
|
||||||
@ -248,18 +242,14 @@ int linux_spi_init(void)
|
|||||||
|
|
||||||
if (register_shutdown(linux_spi_shutdown, spi_data)) {
|
if (register_shutdown(linux_spi_shutdown, spi_data)) {
|
||||||
free(spi_data);
|
free(spi_data);
|
||||||
ret = 1;
|
|
||||||
goto init_err;
|
goto init_err;
|
||||||
}
|
}
|
||||||
register_spi_master(&spi_master_linux);
|
register_spi_master(&spi_master_linux);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
init_err:
|
init_err:
|
||||||
if (fd != -1) {
|
close(fd);
|
||||||
close(fd);
|
return 1;
|
||||||
fd = -1;
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // CONFIG_LINUX_SPI == 1
|
#endif // CONFIG_LINUX_SPI == 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user