Remove unused error return from API that cannot fail

No implementation of fpu_kern_enter() can fail, and it was causing needless
error checking boilerplate and confusion. Change the return code to void to
match reality.

(This trivial change took nine days to land because of the commit hook on
sys/dev/random.  Please consider removing the hook or otherwise lowering the
bar -- secteam never seems to have free time to review patches.)

Reported by:	Lachlan McIlroy <Lachlan.McIlroy AT isilon.com>
Reviewed by:	delphij
Approved by:	secteam (delphij)
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D14380
This commit is contained in:
Conrad Meyer 2018-02-23 20:15:19 +00:00
parent 5e246cb89b
commit 849ce31a82
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=329878
13 changed files with 34 additions and 63 deletions

View File

@ -965,7 +965,7 @@ fpu_kern_ctx_savefpu(struct fpu_kern_ctx *ctx)
return ((struct savefpu *)p);
}
int
void
fpu_kern_enter(struct thread *td, struct fpu_kern_ctx *ctx, u_int flags)
{
struct pcb *pcb;
@ -997,11 +997,11 @@ fpu_kern_enter(struct thread *td, struct fpu_kern_ctx *ctx, u_int flags)
fpurestore(fpu_initialstate);
set_pcb_flags(pcb, PCB_KERNFPU | PCB_FPUNOSAVE |
PCB_FPUINITDONE);
return (0);
return;
}
if ((flags & FPU_KERN_KTHR) != 0 && is_fpu_kern_thread(0)) {
ctx->flags = FPU_KERN_CTX_DUMMY | FPU_KERN_CTX_INUSE;
return (0);
return;
}
KASSERT(!PCB_USER_FPU(pcb) || pcb->pcb_save ==
get_pcb_user_save_pcb(pcb), ("mangled pcb_save"));
@ -1013,7 +1013,7 @@ fpu_kern_enter(struct thread *td, struct fpu_kern_ctx *ctx, u_int flags)
pcb->pcb_save = fpu_kern_ctx_savefpu(ctx);
set_pcb_flags(pcb, PCB_KERNFPU);
clear_pcb_flags(pcb, PCB_FPUINITDONE);
return (0);
return;
}
int

View File

@ -72,7 +72,7 @@ int fputrap_x87(void);
void fpuuserinited(struct thread *td);
struct fpu_kern_ctx *fpu_kern_alloc_ctx(u_int flags);
void fpu_kern_free_ctx(struct fpu_kern_ctx *ctx);
int fpu_kern_enter(struct thread *td, struct fpu_kern_ctx *ctx,
void fpu_kern_enter(struct thread *td, struct fpu_kern_ctx *ctx,
u_int flags);
int fpu_kern_leave(struct thread *td, struct fpu_kern_ctx *ctx);
int fpu_kern_thread(u_int flags);

View File

@ -256,7 +256,7 @@ fpu_kern_free_ctx(struct fpu_kern_ctx *ctx)
free(ctx, M_FPUKERN_CTX);
}
int
void
fpu_kern_enter(struct thread *td, struct fpu_kern_ctx *ctx, u_int flags)
{
struct pcb *pcb;
@ -279,12 +279,12 @@ fpu_kern_enter(struct thread *td, struct fpu_kern_ctx *ctx, u_int flags)
vfp_enable();
pcb->pcb_fpflags |= PCB_FP_KERN | PCB_FP_NOSAVE |
PCB_FP_STARTED;
return (0);
return;
}
if ((flags & FPU_KERN_KTHR) != 0 && is_fpu_kern_thread(0)) {
ctx->flags = FPU_KERN_CTX_DUMMY | FPU_KERN_CTX_INUSE;
return (0);
return;
}
/*
* Check either we are already using the VFP in the kernel, or
@ -300,7 +300,7 @@ fpu_kern_enter(struct thread *td, struct fpu_kern_ctx *ctx, u_int flags)
pcb->pcb_fpflags |= PCB_FP_KERN;
pcb->pcb_fpflags &= ~PCB_FP_STARTED;
return (0);
return;
}
int

View File

@ -60,7 +60,7 @@ struct fpu_kern_ctx;
struct fpu_kern_ctx *fpu_kern_alloc_ctx(u_int);
void fpu_kern_free_ctx(struct fpu_kern_ctx *);
int fpu_kern_enter(struct thread *, struct fpu_kern_ctx *, u_int);
void fpu_kern_enter(struct thread *, struct fpu_kern_ctx *, u_int);
int fpu_kern_leave(struct thread *, struct fpu_kern_ctx *);
int fpu_kern_thread(u_int);
int is_fpu_kern_thread(u_int);

View File

@ -577,10 +577,8 @@ aesni_cipher_setup(struct aesni_session *ses, struct cryptoini *encini,
kt = is_fpu_kern_thread(0) || (encini == NULL);
if (!kt) {
ACQUIRE_CTX(ctxidx, ctx);
error = fpu_kern_enter(curthread, ctx,
fpu_kern_enter(curthread, ctx,
FPU_KERN_NORMAL | FPU_KERN_KTHR);
if (error != 0)
goto out;
}
error = 0;
@ -590,7 +588,6 @@ aesni_cipher_setup(struct aesni_session *ses, struct cryptoini *encini,
if (!kt) {
fpu_kern_leave(curthread, ctx);
out:
RELEASE_CTX(ctxidx, ctx);
}
return (error);
@ -730,10 +727,8 @@ aesni_cipher_process(struct aesni_session *ses, struct cryptodesc *enccrd,
kt = is_fpu_kern_thread(0);
if (!kt) {
ACQUIRE_CTX(ctxidx, ctx);
error = fpu_kern_enter(curthread, ctx,
fpu_kern_enter(curthread, ctx,
FPU_KERN_NORMAL | FPU_KERN_KTHR);
if (error != 0)
goto out2;
}
/* Do work */
@ -761,7 +756,6 @@ aesni_cipher_process(struct aesni_session *ses, struct cryptodesc *enccrd,
out:
if (!kt) {
fpu_kern_leave(curthread, ctx);
out2:
RELEASE_CTX(ctxidx, ctx);
}
return (error);

View File

@ -467,7 +467,7 @@ armv8_crypto_cipher_process(struct armv8_crypto_session *ses,
struct fpu_kern_ctx *ctx;
uint8_t *buf;
uint8_t iv[AES_BLOCK_LEN];
int allocated, error, i;
int allocated, i;
int encflag, ivlen;
int kt;
@ -477,15 +477,11 @@ armv8_crypto_cipher_process(struct armv8_crypto_session *ses,
if (buf == NULL)
return (ENOMEM);
error = 0;
kt = is_fpu_kern_thread(0);
if (!kt) {
AQUIRE_CTX(i, ctx);
error = fpu_kern_enter(curthread, ctx,
fpu_kern_enter(curthread, ctx,
FPU_KERN_NORMAL | FPU_KERN_KTHR);
if (error != 0)
goto out;
}
if ((enccrd->crd_flags & CRD_F_KEY_EXPLICIT) != 0) {
@ -534,14 +530,13 @@ armv8_crypto_cipher_process(struct armv8_crypto_session *ses,
if (!kt) {
fpu_kern_leave(curthread, ctx);
out:
RELEASE_CTX(i, ctx);
}
if (allocated) {
bzero(buf, enccrd->crd_len);
free(buf, M_ARMV8_CRYPTO);
}
return (error);
return (0);
}
static device_method_t armv8_crypto_methods[] = {

View File

@ -246,12 +246,10 @@ padlock_newsession(device_t dev, uint32_t *sidp, struct cryptoini *cri)
if (macini != NULL) {
td = curthread;
error = fpu_kern_enter(td, ses->ses_fpu_ctx, FPU_KERN_NORMAL |
fpu_kern_enter(td, ses->ses_fpu_ctx, FPU_KERN_NORMAL |
FPU_KERN_KTHR);
if (error == 0) {
error = padlock_hash_setup(ses, macini);
fpu_kern_leave(td, ses->ses_fpu_ctx);
}
error = padlock_hash_setup(ses, macini);
fpu_kern_leave(td, ses->ses_fpu_ctx);
if (error != 0) {
padlock_freesession_one(sc, ses, 0);
return (error);

View File

@ -205,7 +205,7 @@ padlock_cipher_process(struct padlock_session *ses, struct cryptodesc *enccrd,
struct thread *td;
u_char *buf, *abuf;
uint32_t *key;
int allocated, error;
int allocated;
buf = padlock_cipher_alloc(enccrd, crp, &allocated);
if (buf == NULL)
@ -250,10 +250,7 @@ padlock_cipher_process(struct padlock_session *ses, struct cryptodesc *enccrd,
}
td = curthread;
error = fpu_kern_enter(td, ses->ses_fpu_ctx, FPU_KERN_NORMAL |
FPU_KERN_KTHR);
if (error != 0)
goto out;
fpu_kern_enter(td, ses->ses_fpu_ctx, FPU_KERN_NORMAL | FPU_KERN_KTHR);
padlock_cbc(abuf, abuf, enccrd->crd_len / AES_BLOCK_LEN, key, cw,
ses->ses_iv);
fpu_kern_leave(td, ses->ses_fpu_ctx);
@ -270,10 +267,9 @@ padlock_cipher_process(struct padlock_session *ses, struct cryptodesc *enccrd,
AES_BLOCK_LEN, ses->ses_iv);
}
out:
if (allocated) {
bzero(buf, enccrd->crd_len + 16);
free(buf, M_PADLOCK);
}
return (error);
return (0);
}

View File

@ -377,10 +377,7 @@ padlock_hash_process(struct padlock_session *ses, struct cryptodesc *maccrd,
int error;
td = curthread;
error = fpu_kern_enter(td, ses->ses_fpu_ctx, FPU_KERN_NORMAL |
FPU_KERN_KTHR);
if (error != 0)
return (error);
fpu_kern_enter(td, ses->ses_fpu_ctx, FPU_KERN_NORMAL | FPU_KERN_KTHR);
if ((maccrd->crd_flags & CRD_F_KEY_EXPLICIT) != 0)
padlock_hash_key_setup(ses, maccrd->crd_key, maccrd->crd_klen);

View File

@ -194,7 +194,6 @@ efi_enter(void)
{
struct thread *td;
pmap_t curpmap;
int error;
if (efi_runtime == NULL)
return (ENXIO);
@ -202,12 +201,7 @@ efi_enter(void)
curpmap = &td->td_proc->p_vmspace->vm_pmap;
PMAP_LOCK(curpmap);
mtx_lock(&efi_lock);
error = fpu_kern_enter(td, NULL, FPU_KERN_NOCTX);
if (error != 0) {
PMAP_UNLOCK(curpmap);
return (error);
}
fpu_kern_enter(td, NULL, FPU_KERN_NOCTX);
return (efi_arch_enter());
}

View File

@ -101,17 +101,14 @@ random_nehemiah_read(void *buf, u_int c)
size_t count, ret;
uint64_t tmp;
if ((fpu_kern_enter(curthread, fpu_ctx_save, FPU_KERN_NORMAL) == 0)) {
b = buf;
for (count = c; count > 0; count -= ret) {
ret = MIN(VIA_RNG_store(&tmp), count);
memcpy(b, &tmp, ret);
b += ret;
}
fpu_kern_leave(curthread, fpu_ctx_save);
fpu_kern_enter(curthread, fpu_ctx_save, FPU_KERN_NORMAL);
b = buf;
for (count = c; count > 0; count -= ret) {
ret = MIN(VIA_RNG_store(&tmp), count);
memcpy(b, &tmp, ret);
b += ret;
}
else
c = 0;
fpu_kern_leave(curthread, fpu_ctx_save);
return (c);
}

View File

@ -1325,7 +1325,7 @@ fpu_kern_ctx_savefpu(struct fpu_kern_ctx *ctx)
return ((union savefpu *)p);
}
int
void
fpu_kern_enter(struct thread *td, struct fpu_kern_ctx *ctx, u_int flags)
{
struct pcb *pcb;
@ -1334,7 +1334,7 @@ fpu_kern_enter(struct thread *td, struct fpu_kern_ctx *ctx, u_int flags)
if ((flags & FPU_KERN_KTHR) != 0 && is_fpu_kern_thread(0)) {
ctx->flags = FPU_KERN_CTX_DUMMY | FPU_KERN_CTX_INUSE;
return (0);
return;
}
pcb = td->td_pcb;
KASSERT(!PCB_USER_FPU(pcb) || pcb->pcb_save ==
@ -1347,7 +1347,7 @@ fpu_kern_enter(struct thread *td, struct fpu_kern_ctx *ctx, u_int flags)
pcb->pcb_save = fpu_kern_ctx_savefpu(ctx);
pcb->pcb_flags |= PCB_KERNNPX;
pcb->pcb_flags &= ~PCB_NPXINITDONE;
return (0);
return;
}
int

View File

@ -76,7 +76,7 @@ void npx_set_fpregs_xmm(struct save87 *, struct savexmm *);
struct fpu_kern_ctx *fpu_kern_alloc_ctx(u_int flags);
void fpu_kern_free_ctx(struct fpu_kern_ctx *ctx);
int fpu_kern_enter(struct thread *td, struct fpu_kern_ctx *ctx,
void fpu_kern_enter(struct thread *td, struct fpu_kern_ctx *ctx,
u_int flags);
int fpu_kern_leave(struct thread *td, struct fpu_kern_ctx *ctx);
int fpu_kern_thread(u_int flags);