Scanbuild finds a possible null pointer dereference here:

http://www.coreboot.org/~stepan/coreboot-scanbuild/kontron_986lcd-m-scanbuild/report-ehErvY.html#EndPath

There are two ways that I thought of fixing it.

The first way is just to insert an

if (first == NULL) return NULL;

at line 53 and remove the if (first) condition.

The only problem with that is that it makes the change look bigger than it is.

Here's a simpler looking change.  Either one is fine with me.  Boot
tested on s2892.

Signed-off-by: Myles Watson <[email protected]>

Thanks,
Myles
Index: cbv2/src/devices/hypertransport.c
===================================================================
--- cbv2.orig/src/devices/hypertransport.c	2009-05-26 08:31:29.000000000 -0600
+++ cbv2/src/devices/hypertransport.c	2009-05-26 09:07:26.000000000 -0600
@@ -41,35 +41,33 @@
  * so don't do it again
  */
 #define OPT_HT_LINK 0
-        
+
 #if OPT_HT_LINK == 1
 #include <cpu/amd/model_fxx_rev.h>
 #endif
 
-static device_t ht_scan_get_devs(device_t *old_devices)
+static device_t ht_scan_get_devs(device_t * old_devices)
 {
-	device_t first, last;
+	device_t first, last, child;
 	first = *old_devices;
-	last = first;
-	/* Extract the chain of devices to (first through last)
-	 * for the next hypertransport device.
-	 */
-	while(last && last->sibling && 
-		(last->sibling->path.type == DEVICE_PATH_PCI) &&
-		(last->sibling->path.pci.devfn > last->path.pci.devfn)) 
-	{
-		last = last->sibling;
-	}
 	if (first) {
-		device_t child;
-		/* Unlink the chain from the list of old devices */
+		last = first;
+		/* Extract the chain of devices to (first through last)
+		 * for the next hypertransport device.
+		 */
+		while (last->sibling &&
+		       (last->sibling->path.type == DEVICE_PATH_PCI) &&
+		       (last->sibling->path.pci.devfn > last->path.pci.devfn)) {
+			last = last->sibling;
+		}
+
+		/* Unlink the chain from the list of old devices. */
 		*old_devices = last->sibling;
 		last->sibling = 0;
 
-		/* Now add the device to the list of devices on the bus.
-		 */
-		/* Find the last child of our parent */
-		for(child = first->bus->children; child && child->sibling; ) {
+		/* Now add the device to the list of devices on the bus.  */
+		/* Find the last child of our parent. */
+		for (child = first->bus->children; child && child->sibling;) {
 			child = child->sibling;
 		}
 		/* Place the chain on the list of children of their parent. */
-- 
coreboot mailing list: [email protected]
http://www.coreboot.org/mailman/listinfo/coreboot

Reply via email to