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
This commit is contained in:
kib 2014-06-15 05:01:35 +00:00
parent cde29dbd9f
commit c2a9bacdac

View File

@ -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 len)
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 len)
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;