diff options
author | Michael Knudsen <mk@cvs.openbsd.org> | 2011-06-17 07:06:48 +0000 |
---|---|---|
committer | Michael Knudsen <mk@cvs.openbsd.org> | 2011-06-17 07:06:48 +0000 |
commit | 588580a3636f1d2f89071c40a24811393a93accc (patch) | |
tree | fe14f36309c4c36297658840fbee97ea66114ab6 /sys/dev | |
parent | f54f5c33e3808aca4c742c69b64f7a9619f240cb (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/dev')
-rw-r--r-- | sys/dev/bluetooth/bthidev.c | 5 | ||||
-rw-r--r-- | sys/dev/ic/mpi.c | 4 | ||||
-rw-r--r-- | sys/dev/isa/ega.c | 4 | ||||
-rw-r--r-- | sys/dev/pci/drm/drm_drv.c | 5 | ||||
-rw-r--r-- | sys/dev/pci/emuxki.c | 5 | ||||
-rw-r--r-- | sys/dev/pci/isp_pci.c | 8 | ||||
-rw-r--r-- | sys/dev/pci/mpii.c | 4 | ||||
-rw-r--r-- | sys/dev/softraid_crypto.c | 4 | ||||
-rw-r--r-- | sys/dev/usb/hid.c | 4 | ||||
-rw-r--r-- | sys/dev/usb/if_wi_usb.c | 4 | ||||
-rw-r--r-- | sys/dev/usb/umidi.c | 12 | ||||
-rw-r--r-- | sys/dev/usb/uticom.c | 4 | ||||
-rw-r--r-- | sys/dev/usb/uvideo.c | 8 |
13 files changed, 37 insertions, 34 deletions
diff --git a/sys/dev/bluetooth/bthidev.c b/sys/dev/bluetooth/bthidev.c index 5ae67ea721f..11b3b277a6e 100644 --- a/sys/dev/bluetooth/bthidev.c +++ b/sys/dev/bluetooth/bthidev.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bthidev.c,v 1.8 2010/08/05 13:13:17 miod Exp $ */ +/* $OpenBSD: bthidev.c,v 1.9 2011/06/17 07:06:46 mk Exp $ */ /* $NetBSD: bthidev.c,v 1.16 2008/08/06 15:01:23 plunky Exp $ */ /*- @@ -228,7 +228,8 @@ bthidev_attach(struct device *parent, struct device *self, void *aux) return; } sc->sc_dlen = bda->bd_hid.hid_dlen; - sc->sc_desc = malloc(bda->bd_hid.hid_dlen, M_BTHIDEV, M_WAITOK); + sc->sc_desc = malloc(bda->bd_hid.hid_dlen, M_BTHIDEV, + M_WAITOK | M_CANFAIL); if (sc->sc_desc == NULL) { printf(": no memory\n"); return; diff --git a/sys/dev/ic/mpi.c b/sys/dev/ic/mpi.c index b4c58493007..cc4251c2220 100644 --- a/sys/dev/ic/mpi.c +++ b/sys/dev/ic/mpi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mpi.c,v 1.171 2011/04/27 06:06:30 dlg Exp $ */ +/* $OpenBSD: mpi.c,v 1.172 2011/06/17 07:06:46 mk Exp $ */ /* * Copyright (c) 2005, 2006, 2009 David Gwynne <dlg@openbsd.org> @@ -3409,7 +3409,7 @@ mpi_create_sensors(struct mpi_softc *sc) return (0); sc->sc_sensors = malloc(sizeof(struct ksensor) * vol, - M_DEVBUF, M_WAITOK|M_ZERO); + M_DEVBUF, M_WAITOK|M_CANFAIL|M_ZERO); if (sc->sc_sensors == NULL) return (1); diff --git a/sys/dev/isa/ega.c b/sys/dev/isa/ega.c index 4338661533a..061a7c36799 100644 --- a/sys/dev/isa/ega.c +++ b/sys/dev/isa/ega.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ega.c,v 1.15 2009/09/05 14:09:35 miod Exp $ */ +/* $OpenBSD: ega.c,v 1.16 2011/06/17 07:06:47 mk Exp $ */ /* $NetBSD: ega.c,v 1.4.4.1 2000/06/30 16:27:47 simonb Exp $ */ /* @@ -842,7 +842,7 @@ ega_load_font(v, cookie, data) if (vc->vc_fonts[slot] != NULL) return (EEXIST); - f = malloc(sizeof(struct egafont), M_DEVBUF, M_WAITOK); + f = malloc(sizeof(struct egafont), M_DEVBUF, M_WAITOK | M_CANFAIL); if (f == NULL) return (ENOMEM); strlcpy(f->name, data->name, sizeof(f->name)); diff --git a/sys/dev/pci/drm/drm_drv.c b/sys/dev/pci/drm/drm_drv.c index 9eb142ff6b1..18338918e48 100644 --- a/sys/dev/pci/drm/drm_drv.c +++ b/sys/dev/pci/drm/drm_drv.c @@ -1,4 +1,4 @@ -/* $OpenBSD: drm_drv.c,v 1.93 2011/06/02 18:22:00 weerd Exp $ */ +/* $OpenBSD: drm_drv.c,v 1.94 2011/06/17 07:06:47 mk Exp $ */ /*- * Copyright 2007-2009 Owain G. Ainsworth <oga@openbsd.org> * Copyright © 2008 Intel Corporation @@ -1566,7 +1566,8 @@ drm_gem_load_uao(bus_dma_tag_t dmat, bus_dmamap_t map, struct uvm_object *uao, * This is really quite ugly, but nothing else would need * bus_dmamap_load_uao() yet. */ - segs = malloc(npages * sizeof(*segs), M_DRM, M_WAITOK | M_ZERO); + segs = malloc(npages * sizeof(*segs), M_DRM, + M_WAITOK | M_CANFAIL | M_ZERO); if (segs == NULL) return (ENOMEM); diff --git a/sys/dev/pci/emuxki.c b/sys/dev/pci/emuxki.c index 24dcfbe3b2a..e8691e46f51 100644 --- a/sys/dev/pci/emuxki.c +++ b/sys/dev/pci/emuxki.c @@ -1,4 +1,4 @@ -/* $OpenBSD: emuxki.c,v 1.38 2011/04/03 15:36:02 jasper Exp $ */ +/* $OpenBSD: emuxki.c,v 1.39 2011/06/17 07:06:47 mk Exp $ */ /* $NetBSD: emuxki.c,v 1.1 2001/10/17 18:39:41 jdolecek Exp $ */ /*- @@ -1187,7 +1187,8 @@ emuxki_channel_new(struct emuxki_voice *voice, u_int8_t num) { struct emuxki_channel *chan; - chan = malloc(sizeof(struct emuxki_channel), M_DEVBUF, M_WAITOK); + chan = malloc(sizeof(struct emuxki_channel), M_DEVBUF, + M_WAITOK | M_CANFAIL); if (chan == NULL) return (NULL); diff --git a/sys/dev/pci/isp_pci.c b/sys/dev/pci/isp_pci.c index 52e7401ad35..9de50ae9959 100644 --- a/sys/dev/pci/isp_pci.c +++ b/sys/dev/pci/isp_pci.c @@ -1,4 +1,4 @@ -/* $OpenBSD: isp_pci.c,v 1.55 2011/04/22 23:19:54 deraadt Exp $ */ +/* $OpenBSD: isp_pci.c,v 1.56 2011/06/17 07:06:47 mk Exp $ */ /* $FreeBSD: src/sys/dev/isp/isp_pci.c,v 1.148 2007/06/26 23:08:57 mjacob Exp $*/ /*- * Copyright (c) 1997-2006 by Matthew Jacob @@ -1275,13 +1275,15 @@ isp_pci_mbxdma(struct ispsoftc *isp) return (0); len = isp->isp_maxcmds * sizeof (XS_T *); - isp->isp_xflist = malloc(len, M_DEVBUF, M_WAITOK | M_ZERO); + isp->isp_xflist = malloc(len, M_DEVBUF, + M_WAITOK | M_CANFAIL | M_ZERO); if (isp->isp_xflist == NULL) { isp_prt(isp, ISP_LOGERR, "cannot malloc xflist array"); return (1); } len = isp->isp_maxcmds * sizeof (bus_dmamap_t); - pcs->pci_xfer_dmap = (bus_dmamap_t *) malloc(len, M_DEVBUF, M_WAITOK); + pcs->pci_xfer_dmap = (bus_dmamap_t *) malloc(len, M_DEVBUF, + M_WAITOK | M_CANFAIL); if (pcs->pci_xfer_dmap == NULL) { free(isp->isp_xflist, M_DEVBUF); isp->isp_xflist = NULL; diff --git a/sys/dev/pci/mpii.c b/sys/dev/pci/mpii.c index 1cab14d016b..d1be9cbe1f1 100644 --- a/sys/dev/pci/mpii.c +++ b/sys/dev/pci/mpii.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mpii.c,v 1.42 2011/05/25 00:12:46 dlg Exp $ */ +/* $OpenBSD: mpii.c,v 1.43 2011/06/17 07:06:47 mk Exp $ */ /* * Copyright (c) 2010 Mike Belopuhov <mkb@crypt.org.ru> * Copyright (c) 2009 James Giannoules @@ -5285,7 +5285,7 @@ mpii_create_sensors(struct mpii_softc *sc) int i; sc->sc_sensors = malloc(sizeof(struct ksensor) * sc->sc_vd_count, - M_DEVBUF, M_WAITOK | M_ZERO); + M_DEVBUF, M_WAITOK | M_CANFAIL | M_ZERO); if (sc->sc_sensors == NULL) return (1); sc->sc_nsensors = sc->sc_vd_count; diff --git a/sys/dev/softraid_crypto.c b/sys/dev/softraid_crypto.c index fd359681f7a..3dd097abffc 100644 --- a/sys/dev/softraid_crypto.c +++ b/sys/dev/softraid_crypto.c @@ -1,4 +1,4 @@ -/* $OpenBSD: softraid_crypto.c,v 1.67 2011/06/05 11:09:00 stsp Exp $ */ +/* $OpenBSD: softraid_crypto.c,v 1.68 2011/06/17 07:06:46 mk Exp $ */ /* * Copyright (c) 2007 Marco Peereboom <marco@peereboom.us> * Copyright (c) 2008 Hans-Joerg Hoexer <hshoexer@openbsd.org> @@ -590,7 +590,7 @@ sr_crypto_change_maskkey(struct sr_discipline *sd, c = (u_char *)sd->mds.mdd_crypto.scr_meta->scm_key; ksz = sizeof(sd->mds.mdd_crypto.scr_key); - p = malloc(ksz, M_DEVBUF, M_WAITOK | M_ZERO); + p = malloc(ksz, M_DEVBUF, M_WAITOK | M_CANFAIL | M_ZERO); if (p == NULL) goto out; diff --git a/sys/dev/usb/hid.c b/sys/dev/usb/hid.c index 3e9df98fe29..7cfb771b3ca 100644 --- a/sys/dev/usb/hid.c +++ b/sys/dev/usb/hid.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hid.c,v 1.23 2011/04/05 15:03:02 miod Exp $ */ +/* $OpenBSD: hid.c,v 1.24 2011/06/17 07:06:47 mk Exp $ */ /* $NetBSD: hid.c,v 1.23 2002/07/11 21:14:25 augustss Exp $ */ /* $FreeBSD: src/sys/dev/usb/hid.c,v 1.11 1999/11/17 22:33:39 n_hibma Exp $ */ @@ -89,8 +89,6 @@ hid_start_parse(void *d, int len, enum hid_kind kind) struct hid_data *s; s = malloc(sizeof *s, M_TEMP, M_WAITOK | M_ZERO); - if (s == NULL) - panic("hid_start_parse"); s->start = s->p = d; s->end = (char *)d + len; diff --git a/sys/dev/usb/if_wi_usb.c b/sys/dev/usb/if_wi_usb.c index df32a86c047..5494a9c071d 100644 --- a/sys/dev/usb/if_wi_usb.c +++ b/sys/dev/usb/if_wi_usb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_wi_usb.c,v 1.50 2011/01/25 20:03:35 jakemsr Exp $ */ +/* $OpenBSD: if_wi_usb.c,v 1.51 2011/06/17 07:06:47 mk Exp $ */ /* * Copyright (c) 2003 Dale Rahn. All rights reserved. @@ -963,7 +963,7 @@ wi_alloc_nicmem_usb(struct wi_softc *wsc, int len, int *id) return ENOMEM; } - sc->wi_usb_txmem[nmem] = malloc(len, M_DEVBUF, M_WAITOK); + sc->wi_usb_txmem[nmem] = malloc(len, M_DEVBUF, M_WAITOK | M_CANFAIL); if (sc->wi_usb_txmem[nmem] == NULL) { sc->wi_usb_nummem--; return ENOMEM; diff --git a/sys/dev/usb/umidi.c b/sys/dev/usb/umidi.c index 78ae450a612..82fb2e1c50a 100644 --- a/sys/dev/usb/umidi.c +++ b/sys/dev/usb/umidi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: umidi.c,v 1.28 2011/01/25 20:03:36 jakemsr Exp $ */ +/* $OpenBSD: umidi.c,v 1.29 2011/06/17 07:06:47 mk Exp $ */ /* $NetBSD: umidi.c,v 1.16 2002/07/11 21:14:32 augustss Exp $ */ /* * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -456,7 +456,7 @@ alloc_all_endpoints_fixed_ep(struct umidi_softc *sc) sc->sc_endpoints = malloc(sizeof(*sc->sc_out_ep)* (sc->sc_out_num_endpoints+ sc->sc_in_num_endpoints), - M_USBDEV, M_WAITOK); + M_USBDEV, M_WAITOK | M_CANFAIL); if (!sc->sc_endpoints) { return USBD_NOMEM; } @@ -599,7 +599,7 @@ alloc_all_endpoints_yamaha(struct umidi_softc *sc) sc->sc_endpoints = malloc(sizeof(struct umidi_endpoint)* (sc->sc_out_num_endpoints+ sc->sc_in_num_endpoints), - M_USBDEV, M_WAITOK); + M_USBDEV, M_WAITOK | M_CANFAIL); if (!sc->sc_endpoints) return USBD_NOMEM; if (sc->sc_out_num_endpoints) { @@ -641,7 +641,7 @@ alloc_all_endpoints_genuine(struct umidi_softc *sc) interface_desc = usbd_get_interface_descriptor(sc->sc_iface); num_ep = interface_desc->bNumEndpoints; sc->sc_endpoints = p = malloc(sizeof(struct umidi_endpoint) * num_ep, - M_USBDEV, M_WAITOK); + M_USBDEV, M_WAITOK | M_CANFAIL); if (!p) return USBD_NOMEM; @@ -734,7 +734,7 @@ alloc_all_jacks(struct umidi_softc *sc) sc->sc_jacks = malloc(sizeof(*sc->sc_out_jacks)*(sc->sc_in_num_jacks+ sc->sc_out_num_jacks), - M_USBDEV, M_WAITOK); + M_USBDEV, M_WAITOK | M_CANFAIL); if (!sc->sc_jacks) return USBD_NOMEM; sc->sc_out_jacks = @@ -975,7 +975,7 @@ alloc_all_mididevs(struct umidi_softc *sc, int nmidi) { sc->sc_num_mididevs = nmidi; sc->sc_mididevs = malloc(sizeof(*sc->sc_mididevs)*nmidi, M_USBDEV, - M_WAITOK | M_ZERO); + M_WAITOK | M_CANFAIL | M_ZERO); if (!sc->sc_mididevs) return USBD_NOMEM; diff --git a/sys/dev/usb/uticom.c b/sys/dev/usb/uticom.c index d3c3d058366..7bfe546e719 100644 --- a/sys/dev/usb/uticom.c +++ b/sys/dev/usb/uticom.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uticom.c,v 1.14 2011/04/05 20:42:43 jsg Exp $ */ +/* $OpenBSD: uticom.c,v 1.15 2011/06/17 07:06:47 mk Exp $ */ /* * Copyright (c) 2005 Dmitry Komissaroff <dxi@mail.ru>. * @@ -925,7 +925,7 @@ uticom_download_fw(struct uticom_softc *sc, int pipeno, return (error); buffer_size = UTICOM_FW_BUFSZ + sizeof(struct uticom_fw_header); - buffer = malloc(buffer_size, M_USBDEV, M_WAITOK); + buffer = malloc(buffer_size, M_USBDEV, M_WAITOK | M_CANFAIL); if (!buffer) { printf("%s: uticom_download_fw: out of memory\n", diff --git a/sys/dev/usb/uvideo.c b/sys/dev/usb/uvideo.c index 2e9712de891..3cbe0c76a84 100644 --- a/sys/dev/usb/uvideo.c +++ b/sys/dev/usb/uvideo.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uvideo.c,v 1.161 2011/04/11 02:04:48 jakemsr Exp $ */ +/* $OpenBSD: uvideo.c,v 1.162 2011/06/17 07:06:47 mk Exp $ */ /* * Copyright (c) 2008 Robert Nagy <robert@openbsd.org> @@ -3242,7 +3242,7 @@ uvideo_queryctrl(void *v, struct v4l2_queryctrl *qctrl) return (EINVAL); } - ctrl_data = malloc(ctrl_len, M_USBDEV, M_WAITOK); + ctrl_data = malloc(ctrl_len, M_USBDEV, M_WAITOK | M_CANFAIL); if (ctrl_data == NULL) { printf("%s: could not allocate control data\n", __func__); return (ENOMEM); @@ -3357,7 +3357,7 @@ uvideo_g_ctrl(void *v, struct v4l2_control *gctrl) return (EINVAL); } - ctrl_data = malloc(ctrl_len, M_USBDEV, M_WAITOK); + ctrl_data = malloc(ctrl_len, M_USBDEV, M_WAITOK | M_CANFAIL); if (ctrl_data == NULL) { printf("%s: could not allocate control data\n", __func__); return (ENOMEM); @@ -3405,7 +3405,7 @@ uvideo_s_ctrl(void *v, struct v4l2_control *sctrl) return (EINVAL); } - ctrl_data = malloc(ctrl_len, M_USBDEV, M_WAITOK); + ctrl_data = malloc(ctrl_len, M_USBDEV, M_WAITOK | M_CANFAIL); if (ctrl_data == NULL) { printf("%s: could not allocate control data\n", __func__); return (ENOMEM); |