⬢ DragonFlyBSD Kernel Audit
DF-5082 / fix.diff
← back to finding ↓ download raw
--- sys/dev/raid/hptrr/hptrr_os_bsd.c
+++ sys/dev/raid/hptrr/hptrr_os_bsd.c
@@ -98,11 +98,20 @@ void *os_map_pci_bar(
     hba->pcibar[index].res = bus_alloc_resource_any(hba->pcidev,
 		hba->pcibar[index].type, &hba->pcibar[index].rid, RF_ACTIVE);
 
+    if (hba->pcibar[index].res == NULL) {
+	os_printk("os_map_pci_bar: failed to allocate PCI BAR %d", index);
+	hba->pcibar[index].base = 0;
+	return 0;
+    }
+
     hba->pcibar[index].base = (char *)rman_get_virtual(hba->pcibar[index].res) + offset;
 	return hba->pcibar[index].base;
 }
 
 void os_unmap_pci_bar(void *osext, void *base)
 {
 	PHBA hba = (PHBA)osext;
 	int index;
 
+	if (base == 0)
+		return;
 	for (index=0; index<6; index++) {
 		if (hba->pcibar[index].base==base) {
+			if (hba->pcibar[index].res == 0)
+				continue;
 			bus_release_resource(hba->pcidev, hba->pcibar[index].type,
 				hba->pcibar[index].rid, hba->pcibar[index].res);