shithub: riscv

Download patch

ref: 78c7ad88ffbfbd2b7a7269d863e5f4be7535b566
parent: 2a531d444cf53419e8d4af716b9937d14ca5b08c
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Fri Nov 26 16:47:15 EST 2021

kernel: add extra negative and power-of-two check to pcibarsize()

--- a/sys/src/9/port/pci.c
+++ b/sys/src/9/port/pci.c
@@ -190,16 +190,16 @@
 			pcicfgrw32(p->tbdf, rno, v, 0);
 		}
 	}
+	size = -size;
 
 	iunlock(&pcicfglock);
 
-	if(size > 0){
-		print("pcibarsize: %T invalid bar rno %x mask %llux\n",
-			p->tbdf, rno, (uvlong)size);
+	if(size < 0 || (size & size-1) != 0){
+		print("pcibarsize: %T invalid bar rno %#x size %#llux mask %#llux\n",
+			p->tbdf, rno, size, -size);
 		return 0;
 	}
-
-	return -size;
+	return size;
 }
 
 void