Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 15 Jun 2014 05:01:36 +0000 (UTC)
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r267492 - head/sys/i386/i386
Message-ID:  <201406150501.s5F51aqC008519@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kib
Date: Sun Jun 15 05:01:35 2014
New Revision: 267492
URL: http://svnweb.freebsd.org/changeset/base/267492

Log:
  Fix some cosmetic issues with the use of kmem_malloc() in the i386 LDT
  sysarch(2) code.
  
  Use M_ZERO instead of explicit bzero(9).  Do not check for failed
  allocation when M_WAITOK is specified (which is specified always).
  Use malloc(9) when allocating memory for the intermediate copy of the
  user-supplied buffer.
  
  Sponsored by:	The FreeBSD Foundation
  MFC after:	1 week

Modified:
  head/sys/i386/i386/sys_machdep.c

Modified: head/sys/i386/i386/sys_machdep.c
==============================================================================
--- head/sys/i386/i386/sys_machdep.c	Sun Jun 15 04:51:53 2014	(r267491)
+++ head/sys/i386/i386/sys_machdep.c	Sun Jun 15 05:01:35 2014	(r267492)
@@ -164,19 +164,14 @@ sysarch(td, uap)
 		break;
 	case I386_SET_LDT:
 		if (kargs.largs.descs != NULL) {
-			lp = (union descriptor *)kmem_malloc(kernel_arena,
+			lp = (union descriptor *)malloc(
 			    kargs.largs.num * sizeof(union descriptor),
-			    M_WAITOK);
-			if (lp == NULL) {
-				error = ENOMEM;
-				break;
-			}
+			    M_TEMP, M_WAITOK);
 			error = copyin(kargs.largs.descs, lp,
 			    kargs.largs.num * sizeof(union descriptor));
 			if (error == 0)
 				error = i386_set_ldt(td, &kargs.largs, lp);
-			kmem_free(kernel_arena, (vm_offset_t)lp,
-			    kargs.largs.num * sizeof(union descriptor));
+			free(lp, M_TEMP);
 		} else {
 			error = i386_set_ldt(td, &kargs.largs, NULL);
 		}
@@ -300,10 +295,7 @@ i386_extend_pcb(struct thread *td)
 	};
 
 	ext = (struct pcb_ext *)kmem_malloc(kernel_arena, ctob(IOPAGES+1),
-	    M_WAITOK);
-	if (ext == 0)
-		return (ENOMEM);
-	bzero(ext, sizeof(struct pcb_ext)); 
+	    M_WAITOK | M_ZERO);
 	/* -16 is so we can convert a trapframe into vm86trapframe inplace */
 	ext->ext_tss.tss_esp0 = td->td_kstack + ctob(KSTACK_PAGES) -
 	    sizeof(struct pcb) - 16;
@@ -474,12 +466,7 @@ user_ldt_alloc(struct mdproc *mdp, int l
  
         new_ldt->ldt_len = len = NEW_MAX_LD(len); 
         new_ldt->ldt_base = (caddr_t)kmem_malloc(kernel_arena, 
-                round_page(len * sizeof(union descriptor)), M_WAITOK);
-        if (new_ldt->ldt_base == NULL) { 
-                free(new_ldt, M_SUBPROC);
-		mtx_lock_spin(&dt_lock);
-                return (NULL);
-        } 
+	    round_page(len * sizeof(union descriptor)), M_WAITOK);
         new_ldt->ldt_refcnt = 1; 
         new_ldt->ldt_active = 0; 
  
@@ -514,12 +501,7 @@ user_ldt_alloc(struct mdproc *mdp, int l
 
 	new_ldt->ldt_len = len = NEW_MAX_LD(len);
 	new_ldt->ldt_base = (caddr_t)kmem_malloc(kernel_arena,
-		len * sizeof(union descriptor), M_WAITOK);
-	if (new_ldt->ldt_base == NULL) {
-		free(new_ldt, M_SUBPROC);
-		mtx_lock_spin(&dt_lock);
-		return (NULL);
-	}
+	    len * sizeof(union descriptor), M_WAITOK);
 	new_ldt->ldt_refcnt = 1;
 	new_ldt->ldt_active = 0;
 



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