#3055 assigned defect

Infinite Loop in PCI Library Auto Bus Enumeration

Reported by: Jeffrey Hill Owned by: Daniel Hellstrom
Priority: normal Milestone:
Component: score Version: 4.11
Severity: normal Keywords:
Cc: Blocked By:
Blocking:

Description

There are some infinite loops in the PCI Library Auto Bus Enumeration, fixed as follows. Also, there is a memory leak at where the pragma indicates.

@@ -76,6 +76,7 @@ static void pci_res_insert(struct pci_res **root, struct pci_res *res)
 	 * sorted after resulting boundary - the boundary after
 	 * the resource.
 	 */
+  if ( size ) {
     while (curr && (curr->boundary >= boundary)) {
       if (curr->boundary == boundary) {
         /* Find Resulting boundary of size */
@@ -97,6 +98,7 @@ static void pci_res_insert(struct pci_res **root, struct pci_res *res)
       last = curr;
       curr = curr->next;
     }
+  }
 
 	if (last == NULL) {
 		/* Insert first in list */
@@ -106,6 +108,7 @@ static void pci_res_insert(struct pci_res **root, struct pci_res *res)
 		last->next = res;
 		res->next = curr;
 	}
+
 }
 
 #ifdef DEBUG
@@ -114,9 +117,9 @@ void pci_res_list_print(struct pci_res *root)
 	if (root == NULL)
 		return;
 
-	printf("RESOURCE LIST:\n");
+	DBG("RESOURCE LIST:\n");
 	while (root) {
-		printf(" SIZE: 0x%08x, BOUNDARY: 0x%08x\n", root->size,
+		DBG(" SIZE: 0x%08x, BOUNDARY: 0x%08x\n", root->size,
 								root->boundary);
 		root = root->next;
 	}
@@ -182,13 +185,13 @@ static void pci_res_reorder(struct pci_res *root)
 		 * and next */
 		hole_size = start_next - start;
 
+		/* Detect dead hole */
+		if (hole_size > 0) {
       /* Find Boundary of START */
       hole_boundary = 1;
       while ((start & hole_boundary) == 0)
         hole_boundary = hole_boundary<<1;
 
-		/* Detect dead hole */
-		if (hole_size > 0) {
 			/* Step through list and try to find a resource that
 			 * can fit into hole. Take into account hole start
 			 * boundary and hole size.
@@ -509,6 +512,7 @@ static void pci_add_res_bus(struct pci_bus *bus, int type)
 {
 	int tindex = type - 1;
 
+#pragma message ("memory leak likely, second pass through here")
 	/* Clear old resources */
 	bus->busres[tindex] = NULL;
 
@@ -580,7 +584,7 @@ static int pci_add_res_dev(struct pci_dev *dev, void *arg)
 		}
 	}
 
-	/* Normal PCI Device as max 6 BARs and a ROM Bar.
+	/* Normal PCI Device has max 6 BARs and a ROM Bar.
 	 * Insert BARs into the sorted resource list.
 	 */
 	for (i = 0; i < DEV_RES_CNT; i++) {
@@ -621,7 +625,7 @@ static uint32_t pci_alloc_res(struct pci_bus *bus, int type,
 
 		if ((starttmp + res->size - 1) > end) {
 			/* Not enough memory available for this resource */
-			printk("PCI[%x:%x:%x]: DEV BAR%d (%d): no resource "
+			DBG("PCI[%x:%x:%x]: DEV BAR%d (%d): no resource "
 			       "assigned\n",
 			       PCI_DEV_EXPAND(dev->busdevfun),
 			       res->bar, res->flags & PCI_RES_TYPE_MASK);
@@ -725,7 +729,7 @@ static void pci_set_bar(struct pci_dev *dev, int residx)
 		tmp = ((res->end-1) & 0xffff0000) | (res->start >> 16);
 
 		DBG("PCI[%x:%x:%x]: BRIDGE BAR 0x%x: 0x%08x [0x30: 0x%x]\n",
-			PCI_DEV_EXPAND(pcidev), 0x1C, tmp, tmp2);
+			PCI_DEV_EXPAND(pcidev), 0x1C, tmp, tmp16);
 		PCI_CFG_W16(pcidev, 0x1C, tmp16);
 		PCI_CFG_W32(pcidev, 0x30, tmp);
 	} else if (is_bridge && (res->bar >= BRIDGE_RES_MEMIO)) {

Change History (3)

comment:1 Changed on Jun 29, 2017 at 4:15:15 PM by Jeffrey Hill

trace

(gdb) bt
#0  pci_res_reorder (root=<optimized out>)
    at /ade/rtems/release/rtems-4-11/c/src/../../cpukit/libpci/pci_cfg_auto.c:191
#1  pci_add_res_bus (type=2, bus=0x8a178ec)
    at /ade/rtems/release/rtems-4-11/c/src/../../cpukit/libpci/pci_cfg_auto.c:532
#2  pci_add_res_dev (dev=0x8a178ec, arg=0x2)
    at /ade/rtems/release/rtems-4-11/c/src/../../cpukit/libpci/pci_cfg_auto.c:552
#3  0x0830cc4c in pci_for_each_child (bus=bus@entry=0x89c5114, 
    func=func@entry=0x830c114 <pci_add_res_dev>, arg=arg@entry=0x2, 
    search=search@entry=0)
    at /ade/rtems/release/rtems-4-11/c/src/../../cpukit/libpci/pci_for_each_child.c:27
#4  0x0830c294 in pci_add_res_bus (type=2, bus=0x89c5114)
    at /ade/rtems/release/rtems-4-11/c/src/../../cpukit/libpci/pci_cfg_auto.c:524
#5  pci_add_res_dev (dev=0x89c5114, arg=0x2)
    at /ade/rtems/release/rtems-4-11/c/src/../../cpukit/libpci/pci_cfg_auto.c:552
#6  0x0830cc4c in pci_for_each_child (bus=bus@entry=0x89c4f3c, 
    func=func@entry=0x830c114 <pci_add_res_dev>, arg=arg@entry=0x2, 
    search=search@entry=0)
    at /ade/rtems/release/rtems-4-11/c/src/../../cpukit/libpci/pci_for_each_child.c:27
#7  0x0830c294 in pci_add_res_bus (type=2, bus=0x89c4f3c)
    at /ade/rtems/release/rtems-4-11/c/src/../../cpukit/libpci/pci_cfg_auto.c:524
#8  pci_add_res_dev (dev=0x89c4f3c, arg=0x2)
    at /ade/rtems/release/rtems-4-11/c/src/../../cpukit/libpci/pci_cfg_auto.c:552
#9  0x0830cc4c in pci_for_each_child (bus=bus@entry=0x89c4e50, 
    func=func@entry=0x830c114 <pci_add_res_dev>, arg=arg@entry=0x2, 
    search=search@entry=0)
    at /ade/rtems/release/rtems-4-11/c/src/../../cpukit/libpci/pci_for_each_child.c:27
#10 0x0830c294 in pci_add_res_bus (type=2, bus=0x89c4e50)
    at /ade/rtems/release/rtems-4-11/c/src/../../cpukit/libpci/pci_cfg_auto.c:524
#11 pci_add_res_dev (dev=0x89c4e50, arg=0x2)
    at /ade/rtems/release/rtems-4-11/c/src/../../cpukit/libpci/pci_cfg_auto.c:552
#12 0x0830cc4c in pci_for_each_child (bus=bus@entry=0x89c4624, 
    func=func@entry=0x830c114 <pci_add_res_dev>, arg=arg@entry=0x2, 
    search=search@entry=0)
    at /ade/rtems/release/rtems-4-11/c/src/../../cpukit/libpci/pci_for_each_chil---Type <return> to 
d.c:27
#13 0x0830c294 in pci_add_res_bus (type=2, bus=0x89c4624)
    at /ade/rtems/release/rtems-4-11/c/src/../../cpukit/libpci/pci_cfg_auto.c:524
#14 pci_add_res_dev (dev=0x89c4624, arg=0x2)
    at /ade/rtems/release/rtems-4-11/c/src/../../cpukit/libpci/pci_cfg_auto.c:552
#15 0x0830cc4c in pci_for_each_child (bus=bus@entry=0x89c4538, 
    func=func@entry=0x830c114 <pci_add_res_dev>, arg=arg@entry=0x2, 
    search=search@entry=0)
    at /ade/rtems/release/rtems-4-11/c/src/../../cpukit/libpci/pci_for_each_child.c:27
#16 0x0830c294 in pci_add_res_bus (type=2, bus=0x89c4538)
    at /ade/rtems/release/rtems-4-11/c/src/../../cpukit/libpci/pci_cfg_auto.c:524
#17 pci_add_res_dev (dev=0x89c4538, arg=0x2)
    at /ade/rtems/release/rtems-4-11/c/src/../../cpukit/libpci/pci_cfg_auto.c:552
#18 0x0830cc4c in pci_for_each_child (bus=bus@entry=0x857c9cc <pci_hb>, 
    func=func@entry=0x830c114 <pci_add_res_dev>, arg=arg@entry=0x2, 
    search=search@entry=0)
    at /ade/rtems/release/rtems-4-11/c/src/../../cpukit/libpci/pci_for_each_child.c:27
#19 0x0830c8bc in pci_add_res_bus (bus=<optimized out>, type=2)
    at /ade/rtems/release/rtems-4-11/c/src/../../cpukit/libpci/pci_cfg_auto.c:524
#20 pci_config_auto ()
    at /ade/rtems/release/rtems-4-11/c/src/../../cpukit/libpci/pci_cfg_auto.c:954
#21 0x080678b4 in pciLibInit ()
Last edited on Jun 29, 2017 at 4:18:00 PM by Jeffrey Hill (previous) (diff)

comment:2 Changed on Jun 29, 2017 at 4:16:00 PM by Jeffrey Hill

Last edited on Jun 29, 2017 at 4:17:37 PM by Jeffrey Hill (previous) (diff)

comment:3 Changed on Jun 29, 2017 at 4:17:58 PM by Joel Sherrill

Owner: changed from joel.sherrill@… to Daniel Hellstrom
Status: newassigned

Daniel Hellstrom wrote this code and should review this ticket.

Note: See TracTickets for help on using tickets.