Просмотр исходного кода

Fix virtio-lib panic when no virtual devices enabled.

Signed-off-by: golubovsky <golubovsky@gmail.com>
golubovsky 8 лет назад
Родитель
Сommit
c0a3787672
2 измененных файлов с 4 добавлено и 6 удалено
  1. 2 3
      sys/src/9/port/devvcon.c
  2. 2 3
      sys/src/9/port/virtio_lib.c

+ 2 - 3
sys/src/9/port/devvcon.c

@@ -194,16 +194,15 @@ vconinit(void)
 	uint32_t nvdev;
 
 	print("virtio-serial-pci initializing\n");
-	nvdev = 1;
-	if(0)  // XXX: getvdevnum() fails and panics at boot.
 	nvdev = getvdevnum();
+	if(nvdev <= 0)
+		return;
 	vcons = mallocz(nvdev * sizeof(Vqctl *), 1);
 	if(vcons == nil) {
 		print("no memory to allocate virtual consoles\n");
 		return;
 	}
 	nvcon = 0;
-	if(0)  // XXX: getvdevsbypciid() fails and panics at boot.
 	nvcon = getvdevsbypciid(PCI_DEVICE_ID_VIRTIO_CONSOLE, vcons, nvdev);
 	print("virtio consoles found: %d\n", nvcon);
 	for(int i = 0; i < nvcon; i++) {

+ 2 - 3
sys/src/9/port/virtio_lib.c

@@ -402,13 +402,12 @@ virtiosetup()
 	print("virtio: initializing\n");
 	nvq = initvdevs(nil);
 	if(nvq == 0) {
-		nvq = -1;
+		print("virtio: no devices\n");
 		return;						// nothing found
 	}
 	cvq = mallocz(nvq * sizeof(Vqctl *), 1);
 	if(cvq == nil) {
 		print("virtiosetup: failed to allocate control structures\n");
-		nvq = -1;
 		return;
 	}
 	initvdevs(cvq);
@@ -441,7 +440,7 @@ uint32_t
 getvdevsbypciid(int pciid, Vqctl **vqs, uint32_t n)
 {
 	uint32_t j = 0;
-	if(n < 1)
+	if(n < 1 || nvq <= 0)
 		return 0;
 	for(int i = 0; i < nvq ; i++) {
 		if(cvq[i]->pci->did == pciid)