1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-04-27 23:22:37 +02:00

linux_spi.c: Use one variable to store raw parameter values

Currently, each programmer parameter has their own temp variable to
store their raw value into it. That's not needed since these variables
are only used for a short time to do some configuration and stay unused
then. Thus, use only one variable for all of them.

Signed-off-by: Felix Singer <felixsinger@posteo.net>
Change-Id: I31e0baa2c5800c722a9ba853bcd40d71ed343f6d
Reviewed-on: https://review.coreboot.org/c/flashrom/+/66568
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Thomas Heijligen <src@posteo.de>
This commit is contained in:
Felix Singer 2022-08-09 06:01:55 +02:00 committed by Anastasia Klimchuk
parent 5c644d86ef
commit fddcc379dc

View File

@ -167,7 +167,7 @@ out:
static int linux_spi_init(void) static int linux_spi_init(void)
{ {
char *p, *endp, *dev; char *param_str, *endp;
uint32_t speed_hz = 2 * 1000 * 1000; uint32_t speed_hz = 2 * 1000 * 1000;
/* FIXME: make the following configurable by CLI options. */ /* FIXME: make the following configurable by CLI options. */
/* 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 */
@ -177,12 +177,12 @@ static int linux_spi_init(void)
size_t max_kernel_buf_size; size_t max_kernel_buf_size;
struct linux_spi_data *spi_data; struct linux_spi_data *spi_data;
p = extract_programmer_param_str("spispeed"); param_str = extract_programmer_param_str("spispeed");
if (p && strlen(p)) { if (param_str && strlen(param_str)) {
speed_hz = (uint32_t)strtoul(p, &endp, 10) * 1000; speed_hz = (uint32_t)strtoul(param_str, &endp, 10) * 1000;
if (p == endp || speed_hz == 0) { if (param_str == endp || speed_hz == 0) {
msg_perr("%s: invalid clock: %s kHz\n", __func__, p); msg_perr("%s: invalid clock: %s kHz\n", __func__, param_str);
free(p); free(param_str);
return 1; return 1;
} }
} else { } else {
@ -190,24 +190,24 @@ static int linux_spi_init(void)
"kHz clock. Use 'spispeed' parameter to override.\n", "kHz clock. Use 'spispeed' parameter to override.\n",
speed_hz / 1000); speed_hz / 1000);
} }
free(p); free(param_str);
dev = extract_programmer_param_str("dev"); param_str = extract_programmer_param_str("dev");
if (!dev || !strlen(dev)) { if (!param_str || !strlen(param_str)) {
msg_perr("No SPI device given. Use flashrom -p " msg_perr("No SPI device given. Use flashrom -p "
"linux_spi:dev=/dev/spidevX.Y\n"); "linux_spi:dev=/dev/spidevX.Y\n");
free(dev); free(param_str);
return 1; return 1;
} }
msg_pdbg("Using device %s\n", dev); msg_pdbg("Using device %s\n", param_str);
if ((fd = open(dev, O_RDWR)) == -1) { if ((fd = open(param_str, O_RDWR)) == -1) {
msg_perr("%s: failed to open %s: %s\n", __func__, msg_perr("%s: failed to open %s: %s\n", __func__,
dev, strerror(errno)); param_str, strerror(errno));
free(dev); free(param_str);
return 1; return 1;
} }
free(dev); free(param_str);
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",