From c4f57ff4927986ac2c45e1d4a84ad425a9c9aae9 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Mon, 20 May 2013 17:32:48 +0200 Subject: pcuart: malloc error handling, cleanup --- sys/src/9/pc/uartisa.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'sys/src/9/pc/uartisa.c') 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; -- cgit v1.2.3