]> git.lizzy.rs Git - plan9front.git/blobdiff - sys/src/9/pc/uartpci.c
kernel: cleanup makefile for $CONF.$O target
[plan9front.git] / sys / src / 9 / pc / uartpci.c
index ec8ce9e94dd680db6cf88c44dddf729311825325..aed64a1b1e33d7c44e45bd4083d36e4720e3fe44 100644 (file)
@@ -21,17 +21,24 @@ uartpci(int ctlrno, Pcidev* p, int barno, int n, int freq, char* name,
        char buf[64];
        Uart *head, *uart;
 
+       head = malloc(sizeof(Uart)*n);
+       if(head == nil){
+               print("uartpci: no memory for Uarts\n");
+               return nil;
+       }
+
        io = p->mem[barno].bar & ~0x01;
        snprint(buf, sizeof(buf), "%s%d", pciphysuart.name, ctlrno);
        if(ioalloc(io, p->mem[barno].size, 0, buf) < 0){
                print("uartpci: I/O 0x%uX in use\n", io);
+               free(head);
                return nil;
        }
 
-       head = uart = malloc(sizeof(Uart)*n);
+       pcienable(p);
+       uart = head;
        for(i = 0; i < n; i++){
-               ctlr = i8250alloc(io, p->intl, p->tbdf);
-               io += iosize;
+               ctlr = i8250alloc(io + i*iosize, p->intl, p->tbdf);
                if(ctlr == nil)
                        continue;
 
@@ -44,16 +51,20 @@ uartpci(int ctlrno, Pcidev* p, int barno, int n, int freq, char* name,
                        (uart-1)->next = uart;
                uart++;
        }
-
-       if (head) {
-               if(perlehead != nil)
-                       perletail->next = head;
-               else
-                       perlehead = head;
-               for(perletail = head; perletail->next != nil;
-                   perletail = perletail->next)
-                       ;
+       if(head == uart){
+               iofree(io);
+               free(head);
+               return nil;
        }
+
+       if(perlehead != nil)
+               perletail->next = head;
+       else
+               perlehead = head;
+       for(perletail = head; perletail->next != nil;
+           perletail = perletail->next)
+               ;
+
        return head;
 }