summaryrefslogtreecommitdiff
path: root/sys/src
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@gmx.de>2013-05-20 17:32:48 +0200
committercinap_lenrek <cinap_lenrek@gmx.de>2013-05-20 17:32:48 +0200
commitc4f57ff4927986ac2c45e1d4a84ad425a9c9aae9 (patch)
treefc75883a1df76b2ab672d74d3007586e05c9c347 /sys/src
parent6ac8a3ca650ead149ed4062a6b06c92a7a961520 (diff)
pcuart: malloc error handling, cleanup
Diffstat (limited to 'sys/src')
-rw-r--r--sys/src/9/pc/uartisa.c10
-rw-r--r--sys/src/9/pc/uartpci.c34
2 files changed, 30 insertions, 14 deletions
diff --git a/sys/src/9/pc/uartisa.c b/sys/src/9/pc/uartisa.c
index f02080d70..f6b590724 100644
--- a/sys/src/9/pc/uartisa.c
+++ b/sys/src/9/pc/uartisa.c
@@ -18,16 +18,22 @@ uartisa(int ctlrno, ISAConf* isa)
Uart *uart;
char buf[64];
+ uart = malloc(sizeof(Uart));
+ if(uart == nil){
+ print("uartisa: no memory for Uart\n");
+ return nil;
+ }
+
io = isa->port;
snprint(buf, sizeof(buf), "%s%d", isaphysuart.name, ctlrno);
if(ioalloc(io, 8, 0, buf) < 0){
print("uartisa: I/O 0x%uX in use\n", io);
+ free(uart);
return nil;
}
- uart = malloc(sizeof(Uart));
ctlr = i8250alloc(io, isa->irq, BUSUNKNOWN);
- if(uart == nil || ctlr == nil){
+ if(ctlr == nil){
iofree(io);
free(uart);
return nil;
diff --git a/sys/src/9/pc/uartpci.c b/sys/src/9/pc/uartpci.c
index ec8ce9e94..1f97bd930 100644
--- a/sys/src/9/pc/uartpci.c
+++ b/sys/src/9/pc/uartpci.c
@@ -21,17 +21,23 @@ 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);
+ 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 +50,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;
}