summaryrefslogtreecommitdiff
path: root/sys/arch
diff options
context:
space:
mode:
authorMichael Knudsen <mk@cvs.openbsd.org>2011-06-17 07:06:48 +0000
committerMichael Knudsen <mk@cvs.openbsd.org>2011-06-17 07:06:48 +0000
commit588580a3636f1d2f89071c40a24811393a93accc (patch)
treefe14f36309c4c36297658840fbee97ea66114ab6 /sys/arch
parentf54f5c33e3808aca4c742c69b64f7a9619f240cb (diff)
M_WAITOK cleanup of two cases:
1) Allocating with M_WAITOK, checking for NULL, and calling panic() is pointless (malloc() will panic if it can't allocate) so remove the check and the call. 2) Allocating with M_WAITOK, checking for NULL, and then gracefully handling failure to allocate is pointless. Instead also pass M_CANFAIL so malloc() doesn't panic so we can actually handle it gracefully. 1) was done using Coccinelle. Input from oga. ok miod.
Diffstat (limited to 'sys/arch')
-rw-r--r--sys/arch/alpha/eisa/eisa_machdep.c22
-rw-r--r--sys/arch/macppc/macppc/openprom.c5
-rw-r--r--sys/arch/sparc64/sparc64/openprom.c5
3 files changed, 9 insertions, 23 deletions
diff --git a/sys/arch/alpha/eisa/eisa_machdep.c b/sys/arch/alpha/eisa/eisa_machdep.c
index 150af807897..598d3d0eeff 100644
--- a/sys/arch/alpha/eisa/eisa_machdep.c
+++ b/sys/arch/alpha/eisa/eisa_machdep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: eisa_machdep.c,v 1.2 2008/07/25 21:11:14 miod Exp $ */
+/* $OpenBSD: eisa_machdep.c,v 1.3 2011/06/17 07:06:46 mk Exp $ */
/* $NetBSD: eisa_machdep.c,v 1.1 2000/07/29 23:18:47 thorpej Exp $ */
/*-
@@ -176,8 +176,6 @@ eisa_parse_mem(struct ecu_func *ecuf, u_int8_t *dp)
for (i = 0; i < ECUF_MEM_ENTRY_CNT; i++) {
ecum = malloc(sizeof(*ecum), M_DEVBUF, M_ZERO|M_WAITOK);
- if (ecum == NULL)
- panic("%s: can't allocate memory for ecum", __func__);
ecum->ecum_isram = dp[0] & 0x1;
ecum->ecum_unitsize = dp[1] & 0x3;
@@ -209,8 +207,6 @@ eisa_parse_irq(struct ecu_func *ecuf, u_int8_t *dp)
for (i = 0; i < ECUF_IRQ_ENTRY_CNT; i++) {
ecui = malloc(sizeof(*ecui), M_DEVBUF, M_ZERO|M_WAITOK);
- if (ecui == NULL)
- panic("%s: can't allocate memory for ecui", __func__);
ecui->ecui_irq = dp[0] & 0xf;
ecui->ecui_ist = (dp[0] & 0x20) ? IST_LEVEL : IST_EDGE;
@@ -237,8 +233,6 @@ eisa_parse_dma(struct ecu_func *ecuf, u_int8_t *dp)
for (i = 0; i < ECUF_DMA_ENTRY_CNT; i++) {
ecud = malloc(sizeof(*ecud), M_DEVBUF, M_ZERO|M_WAITOK);
- if (ecud == NULL)
- panic("%s: can't allocate memory for ecud", __func__);
ecud->ecud_drq = dp[0] & 0x7;
ecud->ecud_shared = dp[0] & 0x40;
@@ -266,8 +260,6 @@ eisa_parse_io(struct ecu_func *ecuf, u_int8_t *dp)
for (i = 0; i < ECUF_IO_ENTRY_CNT; i++) {
ecuio = malloc(sizeof(*ecuio), M_DEVBUF, M_ZERO|M_WAITOK);
- if (ecuio == NULL)
- panic("%s: can't allocate memory for ecuio", __func__);
ecuio->ecuio_addr = dp[1] | (dp[2] << 8);
ecuio->ecuio_size = (dp[0] & 0x1f) + 1;
@@ -396,9 +388,6 @@ eisa_init(eisa_chipset_tag_t ec)
i, offset, eisaid);
#endif
ecud = malloc(sizeof(*ecud), M_DEVBUF, M_ZERO|M_WAITOK);
- if (ecud == NULL)
- panic("%s: can't allocate memory for ecud",
- __func__);
SIMPLEQ_INIT(&ecud->ecud_funcs);
@@ -414,11 +403,8 @@ eisa_init(eisa_chipset_tag_t ec)
*/
cdata = malloc(CBUFSIZE, M_TEMP, M_ZERO|M_WAITOK);
- if (cdata == NULL)
- panic("%s: can't allocate memory for cdata", __func__);
+
data = malloc(CBUFSIZE, M_TEMP, M_ZERO|M_WAITOK);
- if (data == NULL)
- panic("%s: can't allocate memory for data", __func__);
SIMPLEQ_FOREACH(ecud, &ecu_data_list, ecud_list) {
cfgaddr = eisa_config_addr + ecud->ecud_offset;
@@ -532,9 +518,7 @@ eisa_init(eisa_chipset_tag_t ec)
#endif
ecuf = malloc(sizeof(*ecuf), M_DEVBUF, M_WAITOK);
- if (ecuf == NULL)
- panic("%s: can't allocate memory for ecuf",
- __func__);
+
ecuf_init(ecuf);
ecuf->ecuf_funcno = func;
SIMPLEQ_INSERT_TAIL(&ecud->ecud_funcs, ecuf,
diff --git a/sys/arch/macppc/macppc/openprom.c b/sys/arch/macppc/macppc/openprom.c
index 4214edc0ac6..01918683e85 100644
--- a/sys/arch/macppc/macppc/openprom.c
+++ b/sys/arch/macppc/macppc/openprom.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: openprom.c,v 1.1 2007/11/12 19:23:26 kettenis Exp $ */
+/* $OpenBSD: openprom.c,v 1.2 2011/06/17 07:06:46 mk Exp $ */
/* $NetBSD: openprom.c,v 1.4 2002/01/10 06:21:53 briggs Exp $ */
/*
@@ -202,7 +202,8 @@ openpromioctl(dev_t dev, u_long cmd, caddr_t data, int flags, struct proc *p)
error = ENAMETOOLONG;
break;
}
- value = nextprop = malloc(OPROMMAXPARAM, M_TEMP, M_WAITOK);
+ value = nextprop = malloc(OPROMMAXPARAM, M_TEMP,
+ M_WAITOK | M_CANFAIL);
if (nextprop == NULL) {
error = ENOMEM;
break;
diff --git a/sys/arch/sparc64/sparc64/openprom.c b/sys/arch/sparc64/sparc64/openprom.c
index bb67566e0e0..8bd95266089 100644
--- a/sys/arch/sparc64/sparc64/openprom.c
+++ b/sys/arch/sparc64/sparc64/openprom.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: openprom.c,v 1.16 2011/04/22 12:47:26 marco Exp $ */
+/* $OpenBSD: openprom.c,v 1.17 2011/06/17 07:06:46 mk Exp $ */
/* $NetBSD: openprom.c,v 1.4 2002/01/10 06:21:53 briggs Exp $ */
/*
@@ -254,7 +254,8 @@ openpromioctl(dev, cmd, data, flags, p)
error = ENAMETOOLONG;
break;
}
- value = nextprop = malloc(OPROMMAXPARAM, M_TEMP, M_WAITOK);
+ value = nextprop = malloc(OPROMMAXPARAM, M_TEMP,
+ M_WAITOK | M_CANFAIL);
if (nextprop == NULL) {
error = ENOMEM;
break;