pcuart: malloc error handling, cleanup
This commit is contained in:
parent
6ac8a3ca65
commit
c4f57ff492
2 changed files with 30 additions and 14 deletions
|
@ -18,16 +18,22 @@ uartisa(int ctlrno, ISAConf* isa)
|
||||||
Uart *uart;
|
Uart *uart;
|
||||||
char buf[64];
|
char buf[64];
|
||||||
|
|
||||||
|
uart = malloc(sizeof(Uart));
|
||||||
|
if(uart == nil){
|
||||||
|
print("uartisa: no memory for Uart\n");
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
io = isa->port;
|
io = isa->port;
|
||||||
snprint(buf, sizeof(buf), "%s%d", isaphysuart.name, ctlrno);
|
snprint(buf, sizeof(buf), "%s%d", isaphysuart.name, ctlrno);
|
||||||
if(ioalloc(io, 8, 0, buf) < 0){
|
if(ioalloc(io, 8, 0, buf) < 0){
|
||||||
print("uartisa: I/O 0x%uX in use\n", io);
|
print("uartisa: I/O 0x%uX in use\n", io);
|
||||||
|
free(uart);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
uart = malloc(sizeof(Uart));
|
|
||||||
ctlr = i8250alloc(io, isa->irq, BUSUNKNOWN);
|
ctlr = i8250alloc(io, isa->irq, BUSUNKNOWN);
|
||||||
if(uart == nil || ctlr == nil){
|
if(ctlr == nil){
|
||||||
iofree(io);
|
iofree(io);
|
||||||
free(uart);
|
free(uart);
|
||||||
return nil;
|
return nil;
|
||||||
|
|
|
@ -21,17 +21,23 @@ uartpci(int ctlrno, Pcidev* p, int barno, int n, int freq, char* name,
|
||||||
char buf[64];
|
char buf[64];
|
||||||
Uart *head, *uart;
|
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;
|
io = p->mem[barno].bar & ~0x01;
|
||||||
snprint(buf, sizeof(buf), "%s%d", pciphysuart.name, ctlrno);
|
snprint(buf, sizeof(buf), "%s%d", pciphysuart.name, ctlrno);
|
||||||
if(ioalloc(io, p->mem[barno].size, 0, buf) < 0){
|
if(ioalloc(io, p->mem[barno].size, 0, buf) < 0){
|
||||||
print("uartpci: I/O 0x%uX in use\n", io);
|
print("uartpci: I/O 0x%uX in use\n", io);
|
||||||
|
free(head);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
head = uart = malloc(sizeof(Uart)*n);
|
uart = head;
|
||||||
for(i = 0; i < n; i++){
|
for(i = 0; i < n; i++){
|
||||||
ctlr = i8250alloc(io, p->intl, p->tbdf);
|
ctlr = i8250alloc(io + i*iosize, p->intl, p->tbdf);
|
||||||
io += iosize;
|
|
||||||
if(ctlr == nil)
|
if(ctlr == nil)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -44,16 +50,20 @@ uartpci(int ctlrno, Pcidev* p, int barno, int n, int freq, char* name,
|
||||||
(uart-1)->next = uart;
|
(uart-1)->next = uart;
|
||||||
uart++;
|
uart++;
|
||||||
}
|
}
|
||||||
|
if(head == uart){
|
||||||
if (head) {
|
iofree(io);
|
||||||
if(perlehead != nil)
|
free(head);
|
||||||
perletail->next = head;
|
return nil;
|
||||||
else
|
|
||||||
perlehead = head;
|
|
||||||
for(perletail = head; perletail->next != nil;
|
|
||||||
perletail = perletail->next)
|
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(perlehead != nil)
|
||||||
|
perletail->next = head;
|
||||||
|
else
|
||||||
|
perlehead = head;
|
||||||
|
for(perletail = head; perletail->next != nil;
|
||||||
|
perletail = perletail->next)
|
||||||
|
;
|
||||||
|
|
||||||
return head;
|
return head;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue