From b6c57cebe7168de557596af343f5b9758beedb59 Mon Sep 17 00:00:00 2001 From: Sascha Wildner Date: Mon, 5 Dec 2011 11:39:06 +0100 Subject: [PATCH] kernel: Remove some unneeded NULL checks after kmalloc() with M_WAITOK. --- sys/bus/cam/scsi/scsi_sg.c | 5 ----- sys/bus/mmc/mmc.c | 2 -- sys/dev/raid/mfi/mfi.c | 3 --- sys/dev/sound/pcm/buffer.c | 3 --- sys/dev/sound/pcm/feeder.c | 12 ------------ sys/dev/sound/pcm/feeder_rate.c | 7 ------- sys/kern/link_elf_obj.c | 9 --------- sys/kern/sysv_msg.c | 9 --------- sys/libprop/prop_kern.c | 2 -- sys/net/pf/pf_if.c | 5 ----- sys/net/pf/pf_ioctl.c | 8 +------- sys/net/pf/pf_subr.c | 3 --- sys/opencrypto/crypto.c | 10 ---------- sys/opencrypto/cryptodev.c | 2 -- 14 files changed, 1 insertion(+), 79 deletions(-) diff --git a/sys/bus/cam/scsi/scsi_sg.c b/sys/bus/cam/scsi/scsi_sg.c index b0e576d931..dc05b5705b 100644 --- a/sys/bus/cam/scsi/scsi_sg.c +++ b/sys/bus/cam/scsi/scsi_sg.c @@ -271,11 +271,6 @@ sgregister(struct cam_periph *periph, void *arg) } softc = kmalloc(sizeof(*softc), M_DEVBUF, M_WAITOK | M_ZERO); - if (softc == NULL) { - kprintf("sgregister: Unable to allocate softc\n"); - return (CAM_REQ_CMP_ERR); - } - softc->state = SG_STATE_NORMAL; softc->pd_type = SID_TYPE(&cgd->inq_data); softc->sg_timeout = SG_DEFAULT_TIMEOUT / SG_DEFAULT_HZ * hz; diff --git a/sys/bus/mmc/mmc.c b/sys/bus/mmc/mmc.c index a04cd8c92f..fdc72942a6 100644 --- a/sys/bus/mmc/mmc.c +++ b/sys/bus/mmc/mmc.c @@ -1136,8 +1136,6 @@ mmc_discover_cards(struct mmc_softc *sc) if (newcard) { ivar = kmalloc(sizeof(struct mmc_ivars), M_DEVBUF, M_WAITOK | M_ZERO); - if (!ivar) - return; memcpy(ivar->raw_cid, raw_cid, sizeof(raw_cid)); } if (mmcbr_get_ro(sc->dev)) diff --git a/sys/dev/raid/mfi/mfi.c b/sys/dev/raid/mfi/mfi.c index 6bb233afd3..85e3728bf9 100644 --- a/sys/dev/raid/mfi/mfi.c +++ b/sys/dev/raid/mfi/mfi.c @@ -2371,9 +2371,6 @@ mfi_user_command(struct mfi_softc *sc, struct mfi_ioc_passthru *ioc) if (ioc->buf_size > 0) { ioc_buf = kmalloc(ioc->buf_size, M_MFIBUF, M_WAITOK); - if (ioc_buf == NULL) { - return (ENOMEM); - } error = copyin(ioc->buf, ioc_buf, ioc->buf_size); if (error) { device_printf(sc->mfi_dev, "failed to copyin\n"); diff --git a/sys/dev/sound/pcm/buffer.c b/sys/dev/sound/pcm/buffer.c index e695f14d74..fbe91a0772 100644 --- a/sys/dev/sound/pcm/buffer.c +++ b/sys/dev/sound/pcm/buffer.c @@ -24,7 +24,6 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/sound/pcm/buffer.c,v 1.25.2.3 2007/04/26 08:21:43 ariff Exp $ - * $DragonFly: src/sys/dev/sound/pcm/buffer.c,v 1.11 2008/01/06 16:55:51 swildner Exp $ */ #include @@ -182,8 +181,6 @@ sndbuf_resize(struct snd_dbuf *b, unsigned int blkcnt, unsigned int blksz) chn_unlock(b->channel); tmpbuf = kmalloc(blkcnt * blksz, M_DEVBUF, M_WAITOK); - if (tmpbuf == NULL) - return ENOMEM; chn_lock(b->channel); b->blkcnt = blkcnt; b->blksz = blksz; diff --git a/sys/dev/sound/pcm/feeder.c b/sys/dev/sound/pcm/feeder.c index bfe15d8da4..9f31f09759 100644 --- a/sys/dev/sound/pcm/feeder.c +++ b/sys/dev/sound/pcm/feeder.c @@ -24,7 +24,6 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/sound/pcm/feeder.c,v 1.33.2.3 2006/03/07 15:51:19 jhb Exp $ - * $DragonFly: src/sys/dev/sound/pcm/feeder.c,v 1.6 2007/01/04 21:47:03 corecode Exp $ */ #include @@ -63,12 +62,6 @@ feeder_register(void *p) SLIST_INIT(&feedertab); fte = kmalloc(sizeof(*fte), M_FEEDER, M_WAITOK | M_ZERO); - if (fte == NULL) { - kprintf("can't allocate memory for root feeder: %s\n", - fc->name); - - return; - } fte->feederclass = fc; fte->desc = NULL; fte->idx = feedercnt; @@ -88,11 +81,6 @@ feeder_register(void *p) while ((feedercnt < MAXFEEDERS) && (fc->desc[i].type > 0)) { /* kprintf("adding feeder %s, %x -> %x\n", fc->name, fc->desc[i].in, fc->desc[i].out); */ fte = kmalloc(sizeof(*fte), M_FEEDER, M_WAITOK | M_ZERO); - if (fte == NULL) { - kprintf("can't allocate memory for feeder '%s', %x -> %x\n", fc->name, fc->desc[i].in, fc->desc[i].out); - - return; - } fte->feederclass = fc; fte->desc = &fc->desc[i]; fte->idx = feedercnt; diff --git a/sys/dev/sound/pcm/feeder_rate.c b/sys/dev/sound/pcm/feeder_rate.c index 606c143331..88d5394786 100644 --- a/sys/dev/sound/pcm/feeder_rate.c +++ b/sys/dev/sound/pcm/feeder_rate.c @@ -63,7 +63,6 @@ * testing revisions. * * $FreeBSD: src/sys/dev/sound/pcm/feeder_rate.c,v 1.11.2.2 2006/01/29 02:27:28 ariff Exp $ - * $DragonFly: src/sys/dev/sound/pcm/feeder_rate.c,v 1.5 2007/01/04 21:47:03 corecode Exp $ */ #include @@ -510,18 +509,12 @@ feed_rate_init(struct pcm_feeder *f) struct feed_rate_info *info; info = kmalloc(sizeof(*info), M_RATEFEEDER, M_WAITOK | M_ZERO); - if (info == NULL) - return ENOMEM; /* * bufsz = sample from last cycle + conversion space */ info->bufsz = 2 + feeder_rate_buffersize; info->buffer = kmalloc(sizeof(*info->buffer) * info->bufsz, M_RATEFEEDER, M_WAITOK | M_ZERO); - if (info->buffer == NULL) { - kfree(info, M_RATEFEEDER); - return ENOMEM; - } info->rsrc = DSP_DEFAULT_SPEED; info->rdst = DSP_DEFAULT_SPEED; f->data = info; diff --git a/sys/kern/link_elf_obj.c b/sys/kern/link_elf_obj.c index 3872ad3941..380d52f798 100644 --- a/sys/kern/link_elf_obj.c +++ b/sys/kern/link_elf_obj.c @@ -25,7 +25,6 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/kern/link_elf.c,v 1.24 1999/12/24 15:33:36 bde Exp $ - * $DragonFly: src/sys/kern/link_elf.c,v 1.29 2008/08/01 23:11:16 dillon Exp $ */ #include @@ -447,10 +446,6 @@ link_elf_obj_load_file(const char *filename, linker_file_t * result) * Read the elf header from the file. */ hdr = kmalloc(sizeof(*hdr), M_LINKER, M_WAITOK); - if (hdr == NULL) { - error = ENOMEM; - goto out; - } error = vn_rdwr(UIO_READ, vp, (void *)hdr, sizeof(*hdr), 0, UIO_SYSSPACE, IO_NODELOCKED, p->p_ucred, &resid); if (error) @@ -506,10 +501,6 @@ link_elf_obj_load_file(const char *filename, linker_file_t * result) goto out; } shdr = kmalloc(nbytes, M_LINKER, M_WAITOK); - if (shdr == NULL) { - error = ENOMEM; - goto out; - } ef->e_shdr = shdr; error = vn_rdwr(UIO_READ, vp, (caddr_t) shdr, nbytes, hdr->e_shoff, UIO_SYSSPACE, IO_NODELOCKED, p->p_ucred, &resid); diff --git a/sys/kern/sysv_msg.c b/sys/kern/sysv_msg.c index 369e05f718..e0003a9f76 100644 --- a/sys/kern/sysv_msg.c +++ b/sys/kern/sysv_msg.c @@ -156,9 +156,6 @@ msginit(void *dummy) panic("msginfo.msgseg > 32767"); } - if (msgmaps == NULL) - panic("msgmaps is NULL"); - for (i = 0; i < msginfo.msgseg; i++) { if (i > 0) msgmaps[i-1].next = i; @@ -167,9 +164,6 @@ msginit(void *dummy) free_msgmaps = 0; nfree_msgmaps = msginfo.msgseg; - if (msghdrs == NULL) - panic("msghdrs is NULL"); - for (i = 0; i < msginfo.msgtql; i++) { msghdrs[i].msg_type = 0; if (i > 0) @@ -178,9 +172,6 @@ msginit(void *dummy) } free_msghdrs = &msghdrs[0]; - if (msqids == NULL) - panic("msqids is NULL"); - for (i = 0; i < msginfo.msgmni; i++) { msqids[i].msg_qbytes = 0; /* implies entry is available */ msqids[i].msg_perm.seq = 0; /* reset to a known value */ diff --git a/sys/libprop/prop_kern.c b/sys/libprop/prop_kern.c index 629811a71e..90335e9ef6 100644 --- a/sys/libprop/prop_kern.c +++ b/sys/libprop/prop_kern.c @@ -396,8 +396,6 @@ _prop_object_copyin(const struct plistref *pref, const prop_type_t type, * Allow malloc to fail in case pmap would be exhausted. */ buf = kmalloc(pref->pref_len + 1, M_TEMP, M_WAITOK); - if (buf == NULL) - return (ENOMEM); error = copyin(pref->pref_plist, buf, pref->pref_len); if (error) { kfree(buf, M_TEMP); diff --git a/sys/net/pf/pf_if.c b/sys/net/pf/pf_if.c index 955a1b50ed..7866714f56 100644 --- a/sys/net/pf/pf_if.c +++ b/sys/net/pf/pf_if.c @@ -620,11 +620,6 @@ pfi_address_add(struct sockaddr *sa, int af, int net) return; } p = kmalloc(new_max * sizeof(*pfi_buffer), PFI_MTYPE, M_WAITOK); - if (p == NULL) { - kprintf("pfi_address_add: no memory to grow buffer " - "(%d/%d)\n", pfi_buffer_cnt, PFI_BUFFER_MAX); - return; - } memcpy(pfi_buffer, p, pfi_buffer_cnt * sizeof(*pfi_buffer)); /* no need to zero buffer */ kfree(pfi_buffer, PFI_MTYPE); diff --git a/sys/net/pf/pf_ioctl.c b/sys/net/pf/pf_ioctl.c index c9494249c3..e3c66574e8 100644 --- a/sys/net/pf/pf_ioctl.c +++ b/sys/net/pf/pf_ioctl.c @@ -444,8 +444,6 @@ tagname2tag(struct pf_tags *head, char *tagname) /* allocate and fill new struct pf_tagname */ tag = kmalloc(sizeof(*tag), M_TEMP, M_WAITOK); - if (tag == NULL) - return (0); strlcpy(tag->name, tagname, sizeof(tag->name)); tag->tag = new_tagid; tag->ref++; @@ -1135,11 +1133,7 @@ pfioctl(struct dev_ioctl_args *ap) error = EBUSY; break; } - rule = kmalloc(sizeof(struct pf_rule), M_PFRULEPL,M_WAITOK); - if (rule == NULL) { - error = ENOMEM; - break; - } + rule = kmalloc(sizeof(struct pf_rule), M_PFRULEPL, M_WAITOK); bcopy(&pr->rule, rule, sizeof(struct pf_rule)); rule->cuid = ap->a_cred->cr_ruid; rule->cpid = 0; diff --git a/sys/net/pf/pf_subr.c b/sys/net/pf/pf_subr.c index 1491a94d9d..f57da7f755 100644 --- a/sys/net/pf/pf_subr.c +++ b/sys/net/pf/pf_subr.c @@ -71,9 +71,6 @@ hook_establish(struct hook_desc_head *head, int tail, void (*fn)(void *), struct hook_desc *hdp; hdp = kmalloc(sizeof (*hdp), M_DEVBUF, M_WAITOK); - if (hdp == NULL) - return (NULL); - hdp->hd_fn = fn; hdp->hd_arg = arg; if (tail) diff --git a/sys/opencrypto/crypto.c b/sys/opencrypto/crypto.c index 4e0b5aac32..6369ca7f37 100644 --- a/sys/opencrypto/crypto.c +++ b/sys/opencrypto/crypto.c @@ -220,11 +220,6 @@ crypto_init(void) crypto_drivers_num = CRYPTO_DRIVERS_INITIAL; crypto_drivers = kmalloc(crypto_drivers_num * sizeof(struct cryptocap), M_CRYPTO_DATA, M_WAITOK | M_ZERO); - if (crypto_drivers == NULL) { - kprintf("crypto_init: cannot malloc driver table\n"); - error = ENOMEM; - goto bad; - } for (n = 0; n < ncpus; ++n) { tdinfo = &tdinfo_array[n]; @@ -523,11 +518,6 @@ crypto_get_driverid(device_t dev, int flags) newdrv = kmalloc(2 * crypto_drivers_num * sizeof(struct cryptocap), M_CRYPTO_DATA, M_WAITOK|M_ZERO); - if (newdrv == NULL) { - CRYPTO_DRIVER_UNLOCK(); - kprintf("crypto: no space to expand driver table!\n"); - return -1; - } bcopy(crypto_drivers, newdrv, crypto_drivers_num * sizeof(struct cryptocap)); diff --git a/sys/opencrypto/cryptodev.c b/sys/opencrypto/cryptodev.c index d601b52f2c..f49ad42725 100644 --- a/sys/opencrypto/cryptodev.c +++ b/sys/opencrypto/cryptodev.c @@ -777,8 +777,6 @@ csecreate(struct fcrypt *fcr, u_int64_t sid, caddr_t key, u_int64_t keylen, struct csession *cse; cse = kmalloc(sizeof(struct csession), M_XDATA, M_WAITOK | M_ZERO); - if (cse == NULL) - return NULL; lockinit(&cse->lock, "cryptodev", 0, LK_CANRECURSE); cse->key = key; cse->keylen = keylen/8; -- 2.41.0