aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjoern A. Zeeb <bz@FreeBSD.org>2005-04-25 10:18:24 +0000
committerBjoern A. Zeeb <bz@FreeBSD.org>2005-04-25 10:18:24 +0000
commit261a19c1eee477ec374b29f8f94e198e56e4f8d6 (patch)
tree3f1907ed11e412a3e95540e6eab366713e04cbbf
parent1b301a7fa5914f5df2f5ef0ed88b85ca339beeef (diff)
downloadsrc-261a19c1eee477ec374b29f8f94e198e56e4f8d6.tar.gz
src-261a19c1eee477ec374b29f8f94e198e56e4f8d6.zip
Deal with failed malloc calls[1].
While there also check for failed device_add_child calls. Found by: Coventry Analysis tool[1]. Submitted by: sam[1] Approved by: pjd (mentor) MFC after: 1 week
Notes
Notes: svn path=/head/; revision=145501
-rw-r--r--sys/dev/sk/if_sk.c22
-rw-r--r--sys/pci/if_sk.c22
2 files changed, 44 insertions, 0 deletions
diff --git a/sys/dev/sk/if_sk.c b/sys/dev/sk/if_sk.c
index 44bd447e58e6..9f148a1c72f4 100644
--- a/sys/dev/sk/if_sk.c
+++ b/sys/dev/sk/if_sk.c
@@ -1821,13 +1821,35 @@ skc_attach(dev)
}
sc->sk_devs[SK_PORT_A] = device_add_child(dev, "sk", -1);
+ if (sc->sk_devs[SK_PORT_A] == NULL) {
+ device_printf(dev, "failed to add child for PORT_A\n");
+ error = ENXIO;
+ goto fail;
+ }
port = malloc(sizeof(int), M_DEVBUF, M_NOWAIT);
+ if (port == NULL) {
+ device_printf(dev, "failed to allocate memory for "
+ "ivars of PORT_A\n");
+ error = ENXIO;
+ goto fail;
+ }
*port = SK_PORT_A;
device_set_ivars(sc->sk_devs[SK_PORT_A], port);
if (!(sk_win_read_1(sc, SK_CONFIG) & SK_CONFIG_SINGLEMAC)) {
sc->sk_devs[SK_PORT_B] = device_add_child(dev, "sk", -1);
+ if (sc->sk_devs[SK_PORT_B] == NULL) {
+ device_printf(dev, "failed to add child for PORT_B\n");
+ error = ENXIO;
+ goto fail;
+ }
port = malloc(sizeof(int), M_DEVBUF, M_NOWAIT);
+ if (port == NULL) {
+ device_printf(dev, "failed to allocate memory for "
+ "ivars of PORT_B\n");
+ error = ENXIO;
+ goto fail;
+ }
*port = SK_PORT_B;
device_set_ivars(sc->sk_devs[SK_PORT_B], port);
}
diff --git a/sys/pci/if_sk.c b/sys/pci/if_sk.c
index 44bd447e58e6..9f148a1c72f4 100644
--- a/sys/pci/if_sk.c
+++ b/sys/pci/if_sk.c
@@ -1821,13 +1821,35 @@ skc_attach(dev)
}
sc->sk_devs[SK_PORT_A] = device_add_child(dev, "sk", -1);
+ if (sc->sk_devs[SK_PORT_A] == NULL) {
+ device_printf(dev, "failed to add child for PORT_A\n");
+ error = ENXIO;
+ goto fail;
+ }
port = malloc(sizeof(int), M_DEVBUF, M_NOWAIT);
+ if (port == NULL) {
+ device_printf(dev, "failed to allocate memory for "
+ "ivars of PORT_A\n");
+ error = ENXIO;
+ goto fail;
+ }
*port = SK_PORT_A;
device_set_ivars(sc->sk_devs[SK_PORT_A], port);
if (!(sk_win_read_1(sc, SK_CONFIG) & SK_CONFIG_SINGLEMAC)) {
sc->sk_devs[SK_PORT_B] = device_add_child(dev, "sk", -1);
+ if (sc->sk_devs[SK_PORT_B] == NULL) {
+ device_printf(dev, "failed to add child for PORT_B\n");
+ error = ENXIO;
+ goto fail;
+ }
port = malloc(sizeof(int), M_DEVBUF, M_NOWAIT);
+ if (port == NULL) {
+ device_printf(dev, "failed to allocate memory for "
+ "ivars of PORT_B\n");
+ error = ENXIO;
+ goto fail;
+ }
*port = SK_PORT_B;
device_set_ivars(sc->sk_devs[SK_PORT_B], port);
}