From 4b38c2c0ac5b025eb51482a7f01899e262ee4981 Mon Sep 17 00:00:00 2001 From: Yoshihiro Takahashi Date: Sat, 22 Apr 2000 15:12:52 +0000 Subject: [PATCH] Release allocated resources and return ENXIO on error. --- sys/pc98/cbus/sio.c | 23 ++++++++++++++++------- sys/pc98/pc98/sio.c | 23 ++++++++++++++++------- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/sys/pc98/cbus/sio.c b/sys/pc98/cbus/sio.c index 492b7ee3b3db..2cce6367291d 100644 --- a/sys/pc98/cbus/sio.c +++ b/sys/pc98/cbus/sio.c @@ -1244,8 +1244,10 @@ sioprobe(dev, xrid) /* * If the port is i8251 UART (internal, B98_01) */ - if (pc98_check_if_type(dev, &iod) == -1) + if (pc98_check_if_type(dev, &iod) == -1) { + bus_release_resource(dev, SYS_RES_IOPORT, rid, port); return (ENXIO); + } if (iod.irq > 0) bus_set_resource(dev, SYS_RES_IRQ, 0, iod.irq, 1); if (IS_8251(iod.if_type)) { @@ -1334,14 +1336,18 @@ sioprobe(dev, xrid) mcr_image = 0; rsabase = iobase & 0xfff0; - if (rsabase != iobase) - return(0); + if (rsabase != iobase) { + bus_release_resource(dev, SYS_RES_IOPORT, rid, port); + return (ENXIO); + } iobase += 8; outb(rsabase + rsa_msr, 0x04); outb(rsabase + rsa_frr, 0x00); - if ((inb(rsabase + rsa_srr) & 0x36) != 0x36) - return (0); + if ((inb(rsabase + rsa_srr) & 0x36) != 0x36) { + bus_release_resource(dev, SYS_RES_IOPORT, rid, port); + return (ENXIO); + } outb(rsabase + rsa_ier, 0x00); outb(rsabase + rsa_frr, 0x00); outb(rsabase + rsa_tivsr, 0x00); @@ -1359,7 +1365,8 @@ sioprobe(dev, xrid) default: printf("sio%d: irq configuration error\n", device_get_unit(dev)); - return (0); + bus_release_resource(dev, SYS_RES_IOPORT, rid, port); + return (ENXIO); } outb((isa_get_port(dev) & 0x00ff) | tmp, irqout); } @@ -1761,8 +1768,10 @@ sioattach(dev, xrid) iobase += 8; obufsize = 2048; } - if ((obuf = malloc(obufsize * 2, M_DEVBUF, M_NOWAIT)) == NULL) + if ((obuf = malloc(obufsize * 2, M_DEVBUF, M_NOWAIT)) == NULL) { + bus_release_resource(dev, SYS_RES_IOPORT, rid, port); return ENXIO; + } bzero(obuf, obufsize * 2); #endif diff --git a/sys/pc98/pc98/sio.c b/sys/pc98/pc98/sio.c index 492b7ee3b3db..2cce6367291d 100644 --- a/sys/pc98/pc98/sio.c +++ b/sys/pc98/pc98/sio.c @@ -1244,8 +1244,10 @@ sioprobe(dev, xrid) /* * If the port is i8251 UART (internal, B98_01) */ - if (pc98_check_if_type(dev, &iod) == -1) + if (pc98_check_if_type(dev, &iod) == -1) { + bus_release_resource(dev, SYS_RES_IOPORT, rid, port); return (ENXIO); + } if (iod.irq > 0) bus_set_resource(dev, SYS_RES_IRQ, 0, iod.irq, 1); if (IS_8251(iod.if_type)) { @@ -1334,14 +1336,18 @@ sioprobe(dev, xrid) mcr_image = 0; rsabase = iobase & 0xfff0; - if (rsabase != iobase) - return(0); + if (rsabase != iobase) { + bus_release_resource(dev, SYS_RES_IOPORT, rid, port); + return (ENXIO); + } iobase += 8; outb(rsabase + rsa_msr, 0x04); outb(rsabase + rsa_frr, 0x00); - if ((inb(rsabase + rsa_srr) & 0x36) != 0x36) - return (0); + if ((inb(rsabase + rsa_srr) & 0x36) != 0x36) { + bus_release_resource(dev, SYS_RES_IOPORT, rid, port); + return (ENXIO); + } outb(rsabase + rsa_ier, 0x00); outb(rsabase + rsa_frr, 0x00); outb(rsabase + rsa_tivsr, 0x00); @@ -1359,7 +1365,8 @@ sioprobe(dev, xrid) default: printf("sio%d: irq configuration error\n", device_get_unit(dev)); - return (0); + bus_release_resource(dev, SYS_RES_IOPORT, rid, port); + return (ENXIO); } outb((isa_get_port(dev) & 0x00ff) | tmp, irqout); } @@ -1761,8 +1768,10 @@ sioattach(dev, xrid) iobase += 8; obufsize = 2048; } - if ((obuf = malloc(obufsize * 2, M_DEVBUF, M_NOWAIT)) == NULL) + if ((obuf = malloc(obufsize * 2, M_DEVBUF, M_NOWAIT)) == NULL) { + bus_release_resource(dev, SYS_RES_IOPORT, rid, port); return ENXIO; + } bzero(obuf, obufsize * 2); #endif