sb600spi: rewrite and fix corner case

Specifying spispeed=reserved as programmer parameter resulted in
selecting the default SPI speed instead of aborting. Rewrite the logic
to be more readable.

Corresponding to flashrom svn r1949.
Signed-off-by: default avatarCarl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
Acked-by: default avatarStefan Tauner <stefan.tauner@alumni.tuwien.ac.at>
parent 8e656544
...@@ -387,24 +387,25 @@ static int set_mode(struct pci_dev *dev, uint8_t read_mode) ...@@ -387,24 +387,25 @@ static int set_mode(struct pci_dev *dev, uint8_t read_mode)
static int handle_speed(struct pci_dev *dev) static int handle_speed(struct pci_dev *dev)
{ {
uint32_t tmp; uint32_t tmp;
int8_t spispeed_idx = 3; /* Default to 16.5 MHz */ uint8_t spispeed_idx = 3; /* Default to 16.5 MHz */
char *spispeed = extract_programmer_param("spispeed"); char *spispeed = extract_programmer_param("spispeed");
if (spispeed != NULL) { if (spispeed != NULL) {
if (strcasecmp(spispeed, "reserved") != 0) { unsigned int i;
int i;
for (i = 0; i < ARRAY_SIZE(spispeeds); i++) { for (i = 0; i < ARRAY_SIZE(spispeeds); i++) {
if (strcasecmp(spispeeds[i].name, spispeed) == 0) { if (strcasecmp(spispeeds[i].name, spispeed) == 0) {
spispeed_idx = i; spispeed_idx = i;
break; break;
} }
} }
/* Only Yangtze supports the second half of indices; no 66 MHz before SB8xx. */ /* "reserved" is not a valid speed.
if ((amd_gen < CHIPSET_YANGTZE && spispeed_idx > 3) || * Error out on speeds not present in the spispeeds array.
(amd_gen < CHIPSET_SB89XX && spispeed_idx == 0)) * Only Yangtze supports the second half of indices.
spispeed_idx = -1; * No 66 MHz before SB8xx. */
} if ((strcasecmp(spispeed, "reserved") == 0) ||
if (spispeed_idx < 0) { (i == ARRAY_SIZE(spispeeds)) ||
(amd_gen < CHIPSET_YANGTZE && spispeed_idx > 3) ||
(amd_gen < CHIPSET_SB89XX && spispeed_idx == 0)) {
msg_perr("Error: Invalid spispeed value: '%s'.\n", spispeed); msg_perr("Error: Invalid spispeed value: '%s'.\n", spispeed);
free(spispeed); free(spispeed);
return 1; return 1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment