summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Nordin <nordin@cvs.openbsd.org>2002-06-09 00:07:11 +0000
committerThomas Nordin <nordin@cvs.openbsd.org>2002-06-09 00:07:11 +0000
commit8da07922a47436a174298d85234dbce8454451d9 (patch)
treeec2657e83ec57255e42ce4346f73c9160799b029
parent8909406e37cad52958323c54dd7d9cfb17a55472 (diff)
Handle out of memory gracefully. ok jason@
-rw-r--r--sys/dev/ic/dc.c10
-rw-r--r--sys/dev/ic/mk48txx.c6
2 files changed, 14 insertions, 2 deletions
diff --git a/sys/dev/ic/dc.c b/sys/dev/ic/dc.c
index 622ce487d47..9152c90c62e 100644
--- a/sys/dev/ic/dc.c
+++ b/sys/dev/ic/dc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dc.c,v 1.48 2002/04/18 19:11:18 jason Exp $ */
+/* $OpenBSD: dc.c,v 1.49 2002/06/09 00:07:10 nordin Exp $ */
/*
* Copyright (c) 1997, 1998, 1999
@@ -1476,6 +1476,8 @@ void dc_decode_leaf_sia(sc, l)
struct dc_mediainfo *m;
m = malloc(sizeof(struct dc_mediainfo), M_DEVBUF, M_NOWAIT);
+ if (m == NULL)
+ return;
bzero(m, sizeof(struct dc_mediainfo));
if (l->dc_sia_code == DC_SIA_CODE_10BT)
m->dc_media = IFM_10_T;
@@ -1507,6 +1509,8 @@ void dc_decode_leaf_sym(sc, l)
struct dc_mediainfo *m;
m = malloc(sizeof(struct dc_mediainfo), M_DEVBUF, M_NOWAIT);
+ if (m == NULL)
+ return;
bzero(m, sizeof(struct dc_mediainfo));
if (l->dc_sym_code == DC_SYM_CODE_100BT)
m->dc_media = IFM_100_TX;
@@ -1533,6 +1537,8 @@ void dc_decode_leaf_mii(sc, l)
struct dc_mediainfo *m;
m = malloc(sizeof(struct dc_mediainfo), M_DEVBUF, M_NOWAIT);
+ if (m == NULL)
+ return;
bzero(m, sizeof(struct dc_mediainfo));
/* We abuse IFM_AUTO to represent MII. */
m->dc_media = IFM_AUTO;
@@ -1560,6 +1566,8 @@ void dc_read_srom(sc, bits)
size = 2 << bits;
sc->dc_srom = malloc(size, M_DEVBUF, M_NOWAIT);
+ if (sc->dc_srom == NULL)
+ return;
dc_read_eeprom(sc, (caddr_t)sc->dc_srom, 0, (size / 2), 0);
}
diff --git a/sys/dev/ic/mk48txx.c b/sys/dev/ic/mk48txx.c
index 04652b52f58..5fc58cc2139 100644
--- a/sys/dev/ic/mk48txx.c
+++ b/sys/dev/ic/mk48txx.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mk48txx.c,v 1.3 2002/03/19 01:48:47 jason Exp $ */
+/* $OpenBSD: mk48txx.c,v 1.4 2002/06/09 00:07:10 nordin Exp $ */
/* $NetBSD: mk48txx.c,v 1.7 2001/04/08 17:05:10 tsutsui Exp $ */
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -109,6 +109,10 @@ mk48txx_attach(bt, bh, model, year0)
sz = ALIGN(sizeof(struct todr_chip_handle)) + sizeof(struct mk48txx);
handle = malloc(sz, M_DEVBUF, M_NOWAIT);
+ if (handle == NULL) {
+ printf(": failed to allocate memory");
+ return NULL;
+ }
mk = (struct mk48txx *)((u_long)handle +
ALIGN(sizeof(struct todr_chip_handle)));
handle->cookie = mk;