Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 16 Apr 2011 16:20:52 +0000 (UTC)
From:      Dmitry Chagin <dchagin@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r220730 - head/sys/kern
Message-ID:  <201104161620.p3GGKqc2010591@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: dchagin
Date: Sat Apr 16 16:20:51 2011
New Revision: 220730
URL: http://svn.freebsd.org/changeset/base/220730

Log:
  Remove malloc(9) return value checks when M_WAITOK is used.
  
  MFC after:	2 Week

Modified:
  head/sys/kern/link_elf.c
  head/sys/kern/link_elf_obj.c

Modified: head/sys/kern/link_elf.c
==============================================================================
--- head/sys/kern/link_elf.c	Sat Apr 16 14:56:13 2011	(r220729)
+++ head/sys/kern/link_elf.c	Sat Apr 16 16:20:51 2011	(r220730)
@@ -692,10 +692,6 @@ link_elf_load_file(linker_class_t cls, c
 	 * Read the elf header from the file.
 	 */
 	firstpage = malloc(PAGE_SIZE, M_LINKER, M_WAITOK);
-	if (firstpage == NULL) {
-		error = ENOMEM;
-		goto out;
-	}
 	hdr = (Elf_Ehdr *)firstpage;
 	error = vn_rdwr(UIO_READ, nd.ni_vp, firstpage, PAGE_SIZE, 0,
 	    UIO_SYSSPACE, IO_NODELOCKED, td->td_ucred, NOCRED,
@@ -829,10 +825,6 @@ link_elf_load_file(linker_class_t cls, c
 	}
 #else
 	ef->address = malloc(mapsize, M_LINKER, M_WAITOK);
-	if (ef->address == NULL) {
-		error = ENOMEM;
-		goto out;
-	}
 #endif
 	mapbase = ef->address;
 
@@ -918,10 +910,6 @@ link_elf_load_file(linker_class_t cls, c
 	if (nbytes == 0 || hdr->e_shoff == 0)
 		goto nosyms;
 	shdr = malloc(nbytes, M_LINKER, M_WAITOK | M_ZERO);
-	if (shdr == NULL) {
-		error = ENOMEM;
-		goto out;
-	}
 	error = vn_rdwr(UIO_READ, nd.ni_vp,
 	    (caddr_t)shdr, nbytes, hdr->e_shoff,
 	    UIO_SYSSPACE, IO_NODELOCKED, td->td_ucred, NOCRED,
@@ -944,10 +932,6 @@ link_elf_load_file(linker_class_t cls, c
 	strcnt = shdr[symstrindex].sh_size;
 	ef->strbase = malloc(strcnt, M_LINKER, M_WAITOK);
 
-	if (ef->symbase == NULL || ef->strbase == NULL) {
-		error = ENOMEM;
-		goto out;
-	}
 	error = vn_rdwr(UIO_READ, nd.ni_vp,
 	    ef->symbase, symcnt, shdr[symtabindex].sh_offset,
 	    UIO_SYSSPACE, IO_NODELOCKED, td->td_ucred, NOCRED,
@@ -1318,8 +1302,6 @@ link_elf_lookup_set(linker_file_t lf, co
 
 	len = strlen(name) + sizeof("__start_set_"); /* sizeof includes \0 */
 	setsym = malloc(len, M_LINKER, M_WAITOK);
-	if (setsym == NULL)
-		return (ENOMEM);
 
 	/* get address of first entry */
 	snprintf(setsym, len, "%s%s", "__start_set_", name);

Modified: head/sys/kern/link_elf_obj.c
==============================================================================
--- head/sys/kern/link_elf_obj.c	Sat Apr 16 14:56:13 2011	(r220729)
+++ head/sys/kern/link_elf_obj.c	Sat Apr 16 16:20:51 2011	(r220730)
@@ -476,10 +476,6 @@ link_elf_load_file(linker_class_t cls, c
 
 	/* Read the elf header from the file. */
 	hdr = malloc(sizeof(*hdr), M_LINKER, M_WAITOK);
-	if (hdr == NULL) {
-		error = ENOMEM;
-		goto out;
-	}
 	error = vn_rdwr(UIO_READ, nd.ni_vp, (void *)hdr, sizeof(*hdr), 0,
 	    UIO_SYSSPACE, IO_NODELOCKED, td->td_ucred, NOCRED,
 	    &resid, td);
@@ -536,10 +532,6 @@ link_elf_load_file(linker_class_t cls, c
 		goto out;
 	}
 	shdr = malloc(nbytes, M_LINKER, M_WAITOK);
-	if (shdr == NULL) {
-		error = ENOMEM;
-		goto out;
-	}
 	ef->e_shdr = shdr;
 	error = vn_rdwr(UIO_READ, nd.ni_vp, (caddr_t)shdr, nbytes, hdr->e_shoff,
 	    UIO_SYSSPACE, IO_NODELOCKED, td->td_ucred, NOCRED, &resid, td);
@@ -605,22 +597,12 @@ link_elf_load_file(linker_class_t cls, c
 	if (ef->nrelatab != 0)
 		ef->relatab = malloc(ef->nrelatab * sizeof(*ef->relatab),
 		    M_LINKER, M_WAITOK | M_ZERO);
-	if ((ef->nprogtab != 0 && ef->progtab == NULL) ||
-	    (ef->nreltab != 0 && ef->reltab == NULL) ||
-	    (ef->nrelatab != 0 && ef->relatab == NULL)) {
-		error = ENOMEM;
-		goto out;
-	}
 
 	if (symtabindex == -1)
 		panic("lost symbol table index");
 	/* Allocate space for and load the symbol table */
 	ef->ddbsymcnt = shdr[symtabindex].sh_size / sizeof(Elf_Sym);
 	ef->ddbsymtab = malloc(shdr[symtabindex].sh_size, M_LINKER, M_WAITOK);
-	if (ef->ddbsymtab == NULL) {
-		error = ENOMEM;
-		goto out;
-	}
 	error = vn_rdwr(UIO_READ, nd.ni_vp, (void *)ef->ddbsymtab,
 	    shdr[symtabindex].sh_size, shdr[symtabindex].sh_offset,
 	    UIO_SYSSPACE, IO_NODELOCKED, td->td_ucred, NOCRED,
@@ -637,10 +619,6 @@ link_elf_load_file(linker_class_t cls, c
 	/* Allocate space for and load the symbol strings */
 	ef->ddbstrcnt = shdr[symstrindex].sh_size;
 	ef->ddbstrtab = malloc(shdr[symstrindex].sh_size, M_LINKER, M_WAITOK);
-	if (ef->ddbstrtab == NULL) {
-		error = ENOMEM;
-		goto out;
-	}
 	error = vn_rdwr(UIO_READ, nd.ni_vp, ef->ddbstrtab,
 	    shdr[symstrindex].sh_size, shdr[symstrindex].sh_offset,
 	    UIO_SYSSPACE, IO_NODELOCKED, td->td_ucred, NOCRED,
@@ -660,10 +638,6 @@ link_elf_load_file(linker_class_t cls, c
 		ef->shstrcnt = shdr[shstrindex].sh_size;
 		ef->shstrtab = malloc(shdr[shstrindex].sh_size, M_LINKER,
 		    M_WAITOK);
-		if (ef->shstrtab == NULL) {
-			error = ENOMEM;
-			goto out;
-		}
 		error = vn_rdwr(UIO_READ, nd.ni_vp, ef->shstrtab,
 		    shdr[shstrindex].sh_size, shdr[shstrindex].sh_offset,
 		    UIO_SYSSPACE, IO_NODELOCKED, td->td_ucred, NOCRED,



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201104161620.p3GGKqc2010591>