shithub: riscv

Download patch

ref: 23c05d3235153b150fe2e7cafe7ccbfd64c0058f
parent: 43fb53943e4697c7753090d23db88bbf91ab3cec
author: cinap_lenrek <[email protected]>
date: Tue Apr 24 04:46:23 EDT 2012

sdvirtio: make sure queue sizes are multiple of two

--- a/sys/src/9/pc/sdvirtio.c
+++ b/sys/src/9/pc/sdvirtio.c
@@ -119,7 +119,7 @@
 			sizeof(u16int)), 
 		BY2PG, 0, 0);
 	if(p == nil || q == nil){
-		print("mkvqueue: no memory for Vqueue\n");
+		print("virtio: no memory for Vqueue\n");
 		free(p);
 		free(q);
 		return nil;
@@ -169,12 +169,12 @@
 		if(pcicfgr16(p, 0x2E) != typ)
 			continue;
 		if((vd = malloc(sizeof(*vd))) == nil){
-			print("viopnpdevs: cannot allocate memory for Vdev\n");
+			print("virtio: no memory for Vdev\n");
 			break;
 		}
 		vd->port = p->mem[0].bar & ~0x1;
 		if(ioalloc(vd->port, p->mem[0].size, 0, "virtio") < 0){
-			print("viopnpdevs: port %lux in use\n", vd->port);
+			print("virtio: port %lux in use\n", vd->port);
 			free(vd);
 			continue;
 		}
@@ -188,7 +188,8 @@
 		outb(vd->port+Status, Acknowledge|Driver);
 		for(i=0; i<nelem(vd->queue); i++){
 			outs(vd->port+Qselect, i);
-			if((n = ins(vd->port+Qsize)) == 0)
+			n = ins(vd->port+Qsize);
+			if(n == 0 || (n & (n-1)) != 0)
 				break;
 			if((vd->queue[i] = mkvqueue(n)) == nil)
 				break;