From 849ce31a82eb6cd30968a145000e554d7f7a30d0 Mon Sep 17 00:00:00 2001 From: Conrad Meyer Date: Fri, 23 Feb 2018 20:15:19 +0000 Subject: [PATCH] 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 Reviewed by: delphij Approved by: secteam (delphij) Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D14380 --- sys/amd64/amd64/fpu.c | 8 ++++---- sys/amd64/include/fpu.h | 2 +- sys/arm64/arm64/vfp.c | 8 ++++---- sys/arm64/include/vfp.h | 2 +- sys/crypto/aesni/aesni.c | 10 ++-------- sys/crypto/armv8/armv8_crypto.c | 11 +++-------- sys/crypto/via/padlock.c | 8 +++----- sys/crypto/via/padlock_cipher.c | 10 +++------- sys/crypto/via/padlock_hash.c | 5 +---- sys/dev/efidev/efirt.c | 8 +------- sys/dev/random/nehemiah.c | 17 +++++++---------- sys/i386/i386/npx.c | 6 +++--- sys/i386/include/npx.h | 2 +- 13 files changed, 34 insertions(+), 63 deletions(-) diff --git a/sys/amd64/amd64/fpu.c b/sys/amd64/amd64/fpu.c index ede5ad03af01..72b103963413 100644 --- a/sys/amd64/amd64/fpu.c +++ b/sys/amd64/amd64/fpu.c @@ -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 diff --git a/sys/amd64/include/fpu.h b/sys/amd64/include/fpu.h index b7f686ec6ac9..6b9782e7207b 100644 --- a/sys/amd64/include/fpu.h +++ b/sys/amd64/include/fpu.h @@ -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); diff --git a/sys/arm64/arm64/vfp.c b/sys/arm64/arm64/vfp.c index bf72239eed60..2b810eeb6339 100644 --- a/sys/arm64/arm64/vfp.c +++ b/sys/arm64/arm64/vfp.c @@ -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 diff --git a/sys/arm64/include/vfp.h b/sys/arm64/include/vfp.h index 318ad02a1b6e..b3b0c5758285 100644 --- a/sys/arm64/include/vfp.h +++ b/sys/arm64/include/vfp.h @@ -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); diff --git a/sys/crypto/aesni/aesni.c b/sys/crypto/aesni/aesni.c index c2e860909b97..a077fe51c3d9 100644 --- a/sys/crypto/aesni/aesni.c +++ b/sys/crypto/aesni/aesni.c @@ -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); diff --git a/sys/crypto/armv8/armv8_crypto.c b/sys/crypto/armv8/armv8_crypto.c index 52cb8fcc2182..4f753dc16012 100644 --- a/sys/crypto/armv8/armv8_crypto.c +++ b/sys/crypto/armv8/armv8_crypto.c @@ -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[] = { diff --git a/sys/crypto/via/padlock.c b/sys/crypto/via/padlock.c index f6c6d77f6cb7..e53946b3251a 100644 --- a/sys/crypto/via/padlock.c +++ b/sys/crypto/via/padlock.c @@ -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); diff --git a/sys/crypto/via/padlock_cipher.c b/sys/crypto/via/padlock_cipher.c index 0e4beb85dc58..70d28d30fece 100644 --- a/sys/crypto/via/padlock_cipher.c +++ b/sys/crypto/via/padlock_cipher.c @@ -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); } diff --git a/sys/crypto/via/padlock_hash.c b/sys/crypto/via/padlock_hash.c index ebc88787a934..e7d82c8567ac 100644 --- a/sys/crypto/via/padlock_hash.c +++ b/sys/crypto/via/padlock_hash.c @@ -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); diff --git a/sys/dev/efidev/efirt.c b/sys/dev/efidev/efirt.c index 381da270dc4f..a4d776e930b7 100644 --- a/sys/dev/efidev/efirt.c +++ b/sys/dev/efidev/efirt.c @@ -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()); } diff --git a/sys/dev/random/nehemiah.c b/sys/dev/random/nehemiah.c index 74a1afbfee80..c5f42b83d220 100644 --- a/sys/dev/random/nehemiah.c +++ b/sys/dev/random/nehemiah.c @@ -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); } diff --git a/sys/i386/i386/npx.c b/sys/i386/i386/npx.c index bbb47b86f184..d69f0e936013 100644 --- a/sys/i386/i386/npx.c +++ b/sys/i386/i386/npx.c @@ -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 diff --git a/sys/i386/include/npx.h b/sys/i386/include/npx.h index ed8249e4564e..c69510164f3b 100644 --- a/sys/i386/include/npx.h +++ b/sys/i386/include/npx.h @@ -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);