svn commit: r267492 - head/sys/i386/i386

Konstantin Belousov kib at FreeBSD.org
Sun Jun 15 05:01:36 UTC 2014


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;
 


More information about the svn-src-all mailing list