summaryrefslogtreecommitdiff
path: root/com32
diff options
context:
space:
mode:
authorSebastian Herbszt <herbszt@gmx.de>2008-06-11 22:53:01 +0200
committerH. Peter Anvin <hpa@zytor.com>2008-06-13 09:19:57 -0700
commiteab6f0763744c964eded45b48ec41cb6c1f65cdb (patch)
tree49d2c82074cc796ecede0e0e682751b715343caf /com32
parent2c1e6e2be80c54fcf36f89e9de9ab1a5fba5df87 (diff)
downloadsyslinux-eab6f0763744c964eded45b48ec41cb6c1f65cdb.tar.gz
pci: fix off-by-one error and introduce MAX_PCI_FUNC
In include/sys/pci.h we have #define MAX_PCI_BUSES 255 and struct pci_bus_list { struct pci_bus pci_bus[MAX_PCI_BUSES]; uint8_t count; }; And in lib/pci/scan.c for (bus = 0; bus <= MAX_PCI_BUSES; bus++) { pci_bus_list->pci_bus[bus].pci_device_count = 0; Fix possible overflows and introduce MAX_PCI_FUNC. - Sebastian
Diffstat (limited to 'com32')
-rw-r--r--com32/include/sys/pci.h3
-rw-r--r--com32/lib/pci/scan.c14
2 files changed, 9 insertions, 8 deletions
diff --git a/com32/include/sys/pci.h b/com32/include/sys/pci.h
index a49475b6..3b07ae7c 100644
--- a/com32/include/sys/pci.h
+++ b/com32/include/sys/pci.h
@@ -4,8 +4,9 @@
#include <inttypes.h>
#include <sys/io.h>
+#define MAX_PCI_FUNC 8
#define MAX_PCI_DEVICES 32
-#define MAX_PCI_BUSES 255
+#define MAX_PCI_BUSES 256
typedef uint32_t pciaddr_t;
diff --git a/com32/lib/pci/scan.c b/com32/lib/pci/scan.c
index 94c83bbe..be1a7222 100644
--- a/com32/lib/pci/scan.c
+++ b/com32/lib/pci/scan.c
@@ -351,8 +351,8 @@ int pci_scan(struct pci_bus_list * pci_bus_list, struct pci_device_list * pci_de
dprintf("PCI configuration type %d\n", cfgtype);
dprintf("Scanning PCI Buses\n");
- /* We try to detect 255 buses */
- for (bus = 0; bus <= MAX_PCI_BUSES; bus++) {
+ /* We try to detect 256 buses */
+ for (bus = 0; bus < MAX_PCI_BUSES; bus++) {
dprintf("Probing bus 0x%02x... \n", bus);
@@ -360,9 +360,9 @@ int pci_scan(struct pci_bus_list * pci_bus_list, struct pci_device_list * pci_de
pci_bus_list->pci_bus[bus].pci_device_count = 0;
pci_bus_list->count = 0;;
- for (dev = 0; dev <= 0x1f; dev++) {
- maxfunc = 0;
- for (func = 0; func <= maxfunc; func++) {
+ for (dev = 0; dev < MAX_PCI_DEVICES ; dev++) {
+ maxfunc = 1; /* Assume a single-function device */
+ for (func = 0; func < maxfunc; func++) {
a = pci_mkaddr(bus, dev, func, 0);
did = pci_readl(a);
@@ -374,7 +374,7 @@ int pci_scan(struct pci_bus_list * pci_bus_list, struct pci_device_list * pci_de
hdrtype = pci_readb(a + 0x0e);
if (hdrtype & 0x80)
- maxfunc = 7; /* Multifunction device */
+ maxfunc = MAX_PCI_FUNC; /* Multifunction device */
rid = pci_readb(a + 0x08);
sid = pci_readl(a + 0x2c);
@@ -401,7 +401,7 @@ int pci_scan(struct pci_bus_list * pci_bus_list, struct pci_device_list * pci_de
}
/* Detecting pci buses that have pci devices connected */
- for (bus = 0; bus <= 0xff; bus++) {
+ for (bus = 0; bus < MAX_PCI_BUSES; bus++) {
if (pci_bus_list->pci_bus[bus].pci_device_count > 0) {
pci_bus_list->count++;
}