sb/amd/{cimx,}/sb{700,800,900}: Prevent uninitialized reads

There are two hard things in computer science: cache invalidation,
naming things, and off-by-one errors. -- Anonymous

var_num records the number of initialized entries in the reg_var array.
However, this means the index of the last initialized element is one
less than the value of var_num, so we need to take that into account
when indexing into the array. This has already been fixed in several
other places (eg. sb/amd/pi/hudson/lpc.c), so let's also do so here.

Change-Id: Ibefabaca42866a3f2b22eff979c73badf86ac317
Signed-off-by: Jacob Garber <jgarber1@ualberta.ca>
Found-by: scan-build 8.0.0
Reviewed-on: https://review.coreboot.org/c/coreboot/+/33790
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: David Hendricks <david.hendricks@gmail.com>
Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
This commit is contained in:
Jacob Garber 2019-06-25 12:46:35 -06:00 committed by Martin Roth
parent 198c2e63ac
commit a9bf88b883
4 changed files with 12 additions and 12 deletions

View File

@ -170,11 +170,11 @@ void lpc_enable_childrens_resources(struct device *dev)
pci_write_config32(dev, 0x48, reg_x); pci_write_config32(dev, 0x48, reg_x);
/* Set WideIO for as many IOs found (fall through is on purpose) */ /* Set WideIO for as many IOs found (fall through is on purpose) */
switch (var_num) { switch (var_num) {
case 2: case 3:
pci_write_config16(dev, 0x90, reg_var[2]); pci_write_config16(dev, 0x90, reg_var[2]);
case 1: case 2:
pci_write_config16(dev, 0x66, reg_var[1]); pci_write_config16(dev, 0x66, reg_var[1]);
case 0: case 1:
//pci_write_config16(dev, 0x64, reg_var[0]); //cause filo can not find sata //pci_write_config16(dev, 0x64, reg_var[0]); //cause filo can not find sata
break; break;
} }

View File

@ -168,11 +168,11 @@ void lpc_enable_childrens_resources(struct device *dev)
pci_write_config32(dev, 0x48, reg_x); pci_write_config32(dev, 0x48, reg_x);
/* Set WideIO for as many IOs found (fall through is on purpose) */ /* Set WideIO for as many IOs found (fall through is on purpose) */
switch (var_num) { switch (var_num) {
case 2: case 3:
pci_write_config16(dev, 0x90, reg_var[2]); pci_write_config16(dev, 0x90, reg_var[2]);
case 1: case 2:
pci_write_config16(dev, 0x66, reg_var[1]); pci_write_config16(dev, 0x66, reg_var[1]);
case 0: case 1:
//pci_write_config16(dev, 0x64, reg_var[0]); //cause filo can not find sata //pci_write_config16(dev, 0x64, reg_var[0]); //cause filo can not find sata
break; break;
} }

View File

@ -228,11 +228,11 @@ static void sb700_lpc_enable_childrens_resources(struct device *dev)
pci_write_config32(dev, 0x48, reg_x); pci_write_config32(dev, 0x48, reg_x);
/* Set WideIO for as many IOs found (fall through is on purpose) */ /* Set WideIO for as many IOs found (fall through is on purpose) */
switch (var_num) { switch (var_num) {
case 2: case 3:
pci_write_config16(dev, 0x90, reg_var[2]); pci_write_config16(dev, 0x90, reg_var[2]);
case 1: case 2:
pci_write_config16(dev, 0x66, reg_var[1]); pci_write_config16(dev, 0x66, reg_var[1]);
case 0: case 1:
pci_write_config16(dev, 0x64, reg_var[0]); pci_write_config16(dev, 0x64, reg_var[0]);
break; break;
} }

View File

@ -220,11 +220,11 @@ static void sb800_lpc_enable_childrens_resources(struct device *dev)
pci_write_config32(dev, 0x48, reg_x); pci_write_config32(dev, 0x48, reg_x);
/* Set WideIO for as many IOs found (fall through is on purpose) */ /* Set WideIO for as many IOs found (fall through is on purpose) */
switch (var_num) { switch (var_num) {
case 2: case 3:
pci_write_config16(dev, 0x90, reg_var[2]); pci_write_config16(dev, 0x90, reg_var[2]);
case 1: case 2:
pci_write_config16(dev, 0x66, reg_var[1]); pci_write_config16(dev, 0x66, reg_var[1]);
case 0: case 1:
pci_write_config16(dev, 0x64, reg_var[0]); pci_write_config16(dev, 0x64, reg_var[0]);
break; break;
} }