From: Sascha Wildner Date: Tue, 4 Dec 2012 18:43:47 +0000 (+0100) Subject: kernel: Remove NULL checks after kmalloc(..., M_INTWAIT). X-Git-Tag: v3.4.0rc~739 X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/6ea5f4c4dd1dfa95dff164500cd38eeb78182d9d kernel: Remove NULL checks after kmalloc(..., M_INTWAIT). M_INTWAIT will not return NULL unless M_NULLOK is passed too. --- diff --git a/sys/bus/cam/scsi/scsi_da.c b/sys/bus/cam/scsi/scsi_da.c index 60658a3504..8706d5792f 100644 --- a/sys/bus/cam/scsi/scsi_da.c +++ b/sys/bus/cam/scsi/scsi_da.c @@ -1587,11 +1587,6 @@ dastart(struct cam_periph *periph, union ccb *start_ccb) rcaplong = kmalloc(sizeof(*rcaplong), M_SCSIDA, M_INTWAIT | M_ZERO); - if (rcaplong == NULL) { - kprintf("dastart: Couldn't allocate read_capacity\n"); - /* da_free_periph??? */ - break; - } csio = &start_ccb->csio; scsi_read_capacity_16(csio, /*retries*/ 4, diff --git a/sys/dev/crypto/hifn/hifn7751.c b/sys/dev/crypto/hifn/hifn7751.c index e8fd15a269..71984c5c47 100644 --- a/sys/dev/crypto/hifn/hifn7751.c +++ b/sys/dev/crypto/hifn/hifn7751.c @@ -2513,11 +2513,6 @@ hifn_process(device_t dev, struct cryptop *crp, int hint) } cmd = kmalloc(sizeof(struct hifn_command), M_DEVBUF, M_INTWAIT | M_ZERO); - if (cmd == NULL) { - hifnstats.hst_nomem++; - err = ENOMEM; - goto errout; - } if (crp->crp_flags & CRYPTO_F_IMBUF) { cmd->src_m = (struct mbuf *)crp->crp_buf; diff --git a/sys/dev/netif/ath/ath/if_ath.c b/sys/dev/netif/ath/ath/if_ath.c index 2f2237298c..8449fae50b 100644 --- a/sys/dev/netif/ath/ath/if_ath.c +++ b/sys/dev/netif/ath/ath/if_ath.c @@ -3385,11 +3385,6 @@ ath_descdma_setup(struct ath_softc *sc, /* allocate rx buffers */ bsize = sizeof(struct ath_buf) * nbuf; bf = kmalloc(bsize, M_ATHDEV, M_INTWAIT | M_ZERO); - if (bf == NULL) { - if_printf(ifp, "malloc of %s buffers failed, size %u\n", - dd->dd_name, bsize); - goto fail3; - } dd->dd_bufptr = bf; STAILQ_INIT(head); @@ -3504,10 +3499,6 @@ ath_node_alloc(struct ieee80211vap *vap, const uint8_t mac[IEEE80211_ADDR_LEN]) struct ath_node *an; an = kmalloc(space, M_80211_NODE, M_INTWAIT|M_ZERO); - if (an == NULL) { - /* XXX stat+msg */ - return NULL; - } ath_rate_node_init(sc, an); DPRINTF(sc, ATH_DEBUG_NODE, "%s: an %p\n", __func__, an); @@ -6154,10 +6145,6 @@ ath_ioctl_diag(struct ath_softc *sc, struct ath_diag *ad) * Copy in data. */ indata = kmalloc(insize, M_TEMP, M_INTWAIT); - if (indata == NULL) { - error = ENOMEM; - goto bad; - } error = copyin(ad->ad_in_data, indata, insize); if (error) goto bad; @@ -6171,10 +6158,6 @@ ath_ioctl_diag(struct ath_softc *sc, struct ath_diag *ad) * may want to be more defensive. */ outdata = kmalloc(outsize, M_TEMP, M_INTWAIT); - if (outdata == NULL) { - error = ENOMEM; - goto bad; - } } if (ath_hal_getdiagstate(ah, id, indata, insize, &outdata, &outsize)) { if (outsize < ad->ad_out_size) diff --git a/sys/dev/netif/iwn/if_iwn.c b/sys/dev/netif/iwn/if_iwn.c index 525aa03ba7..1c634cc833 100644 --- a/sys/dev/netif/iwn/if_iwn.c +++ b/sys/dev/netif/iwn/if_iwn.c @@ -4640,12 +4640,6 @@ iwn_scan(struct iwn_softc *sc) uint8_t *buf, *frm, txant; buf = kmalloc(IWN_SCAN_MAXSZ, M_DEVBUF, M_INTWAIT | M_ZERO); - if (buf == NULL) { - device_printf(sc->sc_dev, - "%s: could not allocate buffer for scan command\n", - __func__); - return ENOMEM; - } hdr = (struct iwn_scan_hdr *)buf; /* diff --git a/sys/kern/subr_bus.c b/sys/kern/subr_bus.c index 4a1dcfa03b..6d9612e90a 100644 --- a/sys/kern/subr_bus.c +++ b/sys/kern/subr_bus.c @@ -594,8 +594,6 @@ devclass_find_internal(const char *classname, const char *parentname, PDEBUG(("creating %s", classname)); dc = kmalloc(sizeof(struct devclass) + strlen(classname) + 1, M_BUS, M_INTWAIT | M_ZERO); - if (!dc) - return(NULL); dc->parent = NULL; dc->name = (char*) (dc + 1); strcpy(dc->name, classname); @@ -655,8 +653,6 @@ devclass_add_driver(devclass_t dc, driver_t *driver) PDEBUG(("%s", DRIVERNAME(driver))); dl = kmalloc(sizeof *dl, M_BUS, M_INTWAIT | M_ZERO); - if (!dl) - return(ENOMEM); /* * Compile the driver's methods. Also increase the reference count @@ -816,8 +812,6 @@ devclass_get_devices(devclass_t dc, device_t **devlistp, int *devcountp) count++; list = kmalloc(count * sizeof(device_t), M_TEMP, M_INTWAIT | M_ZERO); - if (list == NULL) - return(ENOMEM); count = 0; for (i = 0; i < dc->maxunit; i++) @@ -1338,8 +1332,6 @@ device_get_children(device_t dev, device_t **devlistp, int *devcountp) count++; list = kmalloc(count * sizeof(device_t), M_TEMP, M_INTWAIT | M_ZERO); - if (!list) - return(ENOMEM); count = 0; TAILQ_FOREACH(child, &dev->children, link) { @@ -1834,8 +1826,6 @@ resource_new_name(const char *name, int unit) new = kmalloc((devtab_count + 1) * sizeof(*new), M_TEMP, M_INTWAIT | M_ZERO); - if (new == NULL) - return(-1); if (devtab && devtab_count > 0) bcopy(devtab, new, devtab_count * sizeof(*new)); new[devtab_count].name = kmalloc(strlen(name) + 1, M_TEMP, M_INTWAIT); @@ -1861,8 +1851,6 @@ resource_new_resname(int j, const char *resname, resource_type type) i = devtab[j].resource_count; new = kmalloc((i + 1) * sizeof(*new), M_TEMP, M_INTWAIT | M_ZERO); - if (new == NULL) - return(-1); if (devtab[j].resources && i > 0) bcopy(devtab[j].resources, new, i * sizeof(*new)); new[i].name = kmalloc(strlen(resname) + 1, M_TEMP, M_INTWAIT); @@ -2223,8 +2211,6 @@ resource_list_add(struct resource_list *rl, int type, int rid, if (rle == NULL) { rle = kmalloc(sizeof(struct resource_list_entry), M_BUS, M_INTWAIT); - if (!rle) - panic("resource_list_add: can't record entry"); SLIST_INSERT_HEAD(rl, rle, link); rle->type = type; rle->rid = rid; diff --git a/sys/netproto/802_11/wlan/ieee80211_hwmp.c b/sys/netproto/802_11/wlan/ieee80211_hwmp.c index 2d730dcba8..0ce7a27e89 100644 --- a/sys/netproto/802_11/wlan/ieee80211_hwmp.c +++ b/sys/netproto/802_11/wlan/ieee80211_hwmp.c @@ -238,10 +238,6 @@ hwmp_vattach(struct ieee80211vap *vap) hs = kmalloc(sizeof(struct ieee80211_hwmp_state), M_80211_VAP, M_INTWAIT | M_ZERO); - if (hs == NULL) { - kprintf("%s: couldn't alloc HWMP state\n", __func__); - return; - } hs->hs_maxhops = IEEE80211_HWMP_DEFAULT_MAXHOPS; callout_init_mp(&hs->hs_roottimer); vap->iv_hwmp = hs; diff --git a/sys/netproto/802_11/wlan/ieee80211_mesh.c b/sys/netproto/802_11/wlan/ieee80211_mesh.c index 725cac2ce6..ddc1db5ceb 100644 --- a/sys/netproto/802_11/wlan/ieee80211_mesh.c +++ b/sys/netproto/802_11/wlan/ieee80211_mesh.c @@ -495,10 +495,6 @@ mesh_vattach(struct ieee80211vap *vap) vap->iv_recv_mgmt = mesh_recv_mgmt; ms = kmalloc(sizeof(struct ieee80211_mesh_state), M_80211_VAP, M_INTWAIT | M_ZERO); - if (ms == NULL) { - kprintf("%s: couldn't alloc MBSS state\n", __func__); - return; - } vap->iv_mesh = ms; ms->ms_seq = 0; ms->ms_flags = (IEEE80211_MESHFLAGS_AP | IEEE80211_MESHFLAGS_FWD); @@ -2583,8 +2579,6 @@ mesh_ioctl_get80211(struct ieee80211vap *vap, struct ieee80211req *ireq) ireq->i_len = len; /* XXX M_WAIT? */ p = kmalloc(len, M_TEMP, M_INTWAIT | M_ZERO); - if (p == NULL) - return ENOMEM; off = 0; TAILQ_FOREACH(rt, &ms->ms_routes, rt_next) { if (off >= len) diff --git a/sys/netproto/802_11/wlan/ieee80211_regdomain.c b/sys/netproto/802_11/wlan/ieee80211_regdomain.c index e7f3c7af54..8371537b06 100644 --- a/sys/netproto/802_11/wlan/ieee80211_regdomain.c +++ b/sys/netproto/802_11/wlan/ieee80211_regdomain.c @@ -242,12 +242,6 @@ ieee80211_alloc_countryie(struct ieee80211com *ic) aie = kmalloc(IEEE80211_COUNTRY_MAX_SIZE, M_80211_NODE_IE, M_INTWAIT | M_ZERO); - if (aie == NULL) { - if_printf(ic->ic_ifp, - "%s: unable to allocate memory for country ie\n", __func__); - /* XXX stat */ - return NULL; - } ie = (struct ieee80211_country_ie *) aie->ie_data; ie->ie = IEEE80211_ELEMID_COUNTRY; if (rd->isocc[0] == '\0') { diff --git a/sys/opencrypto/cryptosoft.c b/sys/opencrypto/cryptosoft.c index e274486562..1f900127cf 100644 --- a/sys/opencrypto/cryptosoft.c +++ b/sys/opencrypto/cryptosoft.c @@ -768,8 +768,6 @@ swcr_compdec(struct cryptodesc *crd, struct swcr_data *sw, * copy in a buffer. */ data = kmalloc(crd->crd_len, M_CRYPTO_DATA, M_INTWAIT); - if (data == NULL) - return (EINVAL); crypto_copydata(flags, buf, crd->crd_skip, crd->crd_len, data); if (crd->crd_flags & CRD_F_COMP) diff --git a/sys/platform/pc32/i386/nexus.c b/sys/platform/pc32/i386/nexus.c index 3a36f10508..9c9ce4aad1 100644 --- a/sys/platform/pc32/i386/nexus.c +++ b/sys/platform/pc32/i386/nexus.c @@ -289,8 +289,6 @@ nexus_add_child(device_t bus, device_t parent, int order, struct nexus_device *ndev; ndev = kmalloc(sizeof(struct nexus_device), M_NEXUSDEV, M_INTWAIT|M_ZERO); - if (!ndev) - return(0); resource_list_init(&ndev->nx_resources); ndev->nx_pcibus = -1; diff --git a/sys/platform/pc64/x86_64/nexus.c b/sys/platform/pc64/x86_64/nexus.c index f5adb64af8..d2ee821564 100644 --- a/sys/platform/pc64/x86_64/nexus.c +++ b/sys/platform/pc64/x86_64/nexus.c @@ -287,8 +287,6 @@ nexus_add_child(device_t bus, device_t parent, int order, struct nexus_device *ndev; ndev = kmalloc(sizeof(struct nexus_device), M_NEXUSDEV, M_INTWAIT|M_ZERO); - if (!ndev) - return(0); resource_list_init(&ndev->nx_resources); ndev->nx_pcibus = -1;