Author: cem
Date: Fri Feb 23 20:15:19 2018
New Revision: 329878
URL: https://svnweb.freebsd.org/changeset/base/329878

Log:
  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

Modified:
  head/sys/amd64/amd64/fpu.c
  head/sys/amd64/include/fpu.h
  head/sys/arm64/arm64/vfp.c
  head/sys/arm64/include/vfp.h
  head/sys/crypto/aesni/aesni.c
  head/sys/crypto/armv8/armv8_crypto.c
  head/sys/crypto/via/padlock.c
  head/sys/crypto/via/padlock_cipher.c
  head/sys/crypto/via/padlock_hash.c
  head/sys/dev/efidev/efirt.c
  head/sys/dev/random/nehemiah.c
  head/sys/i386/i386/npx.c
  head/sys/i386/include/npx.h

Modified: head/sys/amd64/amd64/fpu.c
==============================================================================
--- head/sys/amd64/amd64/fpu.c  Fri Feb 23 20:01:42 2018        (r329877)
+++ head/sys/amd64/amd64/fpu.c  Fri Feb 23 20:15:19 2018        (r329878)
@@ -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 
                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 
        pcb->pcb_save = fpu_kern_ctx_savefpu(ctx);
        set_pcb_flags(pcb, PCB_KERNFPU);
        clear_pcb_flags(pcb, PCB_FPUINITDONE);
-       return (0);
+       return;
 }
 
 int

Modified: head/sys/amd64/include/fpu.h
==============================================================================
--- head/sys/amd64/include/fpu.h        Fri Feb 23 20:01:42 2018        
(r329877)
+++ head/sys/amd64/include/fpu.h        Fri Feb 23 20:15:19 2018        
(r329878)
@@ -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);

Modified: head/sys/arm64/arm64/vfp.c
==============================================================================
--- head/sys/arm64/arm64/vfp.c  Fri Feb 23 20:01:42 2018        (r329877)
+++ head/sys/arm64/arm64/vfp.c  Fri Feb 23 20:15:19 2018        (r329878)
@@ -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 
                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 
        pcb->pcb_fpflags |= PCB_FP_KERN;
        pcb->pcb_fpflags &= ~PCB_FP_STARTED;
 
-       return (0);
+       return;
 }
 
 int

Modified: head/sys/arm64/include/vfp.h
==============================================================================
--- head/sys/arm64/include/vfp.h        Fri Feb 23 20:01:42 2018        
(r329877)
+++ head/sys/arm64/include/vfp.h        Fri Feb 23 20:15:19 2018        
(r329878)
@@ -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);

Modified: head/sys/crypto/aesni/aesni.c
==============================================================================
--- head/sys/crypto/aesni/aesni.c       Fri Feb 23 20:01:42 2018        
(r329877)
+++ head/sys/crypto/aesni/aesni.c       Fri Feb 23 20:15:19 2018        
(r329878)
@@ -577,10 +577,8 @@ aesni_cipher_setup(struct aesni_session *ses, struct c
        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 c
 
        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
        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
 out:
        if (!kt) {
                fpu_kern_leave(curthread, ctx);
-out2:
                RELEASE_CTX(ctxidx, ctx);
        }
        return (error);

Modified: head/sys/crypto/armv8/armv8_crypto.c
==============================================================================
--- head/sys/crypto/armv8/armv8_crypto.c        Fri Feb 23 20:01:42 2018        
(r329877)
+++ head/sys/crypto/armv8/armv8_crypto.c        Fri Feb 23 20:15:19 2018        
(r329878)
@@ -467,7 +467,7 @@ armv8_crypto_cipher_process(struct armv8_crypto_sessio
        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_sessio
        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_sessio
 
        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[] = {

Modified: head/sys/crypto/via/padlock.c
==============================================================================
--- head/sys/crypto/via/padlock.c       Fri Feb 23 20:01:42 2018        
(r329877)
+++ head/sys/crypto/via/padlock.c       Fri Feb 23 20:15:19 2018        
(r329878)
@@ -246,12 +246,10 @@ padlock_newsession(device_t dev, uint32_t *sidp, struc
 
        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);

Modified: head/sys/crypto/via/padlock_cipher.c
==============================================================================
--- head/sys/crypto/via/padlock_cipher.c        Fri Feb 23 20:01:42 2018        
(r329877)
+++ head/sys/crypto/via/padlock_cipher.c        Fri Feb 23 20:15:19 2018        
(r329878)
@@ -205,7 +205,7 @@ padlock_cipher_process(struct padlock_session *ses, st
        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, st
        }
 
        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, st
                    AES_BLOCK_LEN, ses->ses_iv);
        }
 
- out:
        if (allocated) {
                bzero(buf, enccrd->crd_len + 16);
                free(buf, M_PADLOCK);
        }
-       return (error);
+       return (0);
 }

Modified: head/sys/crypto/via/padlock_hash.c
==============================================================================
--- head/sys/crypto/via/padlock_hash.c  Fri Feb 23 20:01:42 2018        
(r329877)
+++ head/sys/crypto/via/padlock_hash.c  Fri Feb 23 20:15:19 2018        
(r329878)
@@ -377,10 +377,7 @@ padlock_hash_process(struct padlock_session *ses, stru
        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);
 

Modified: head/sys/dev/efidev/efirt.c
==============================================================================
--- head/sys/dev/efidev/efirt.c Fri Feb 23 20:01:42 2018        (r329877)
+++ head/sys/dev/efidev/efirt.c Fri Feb 23 20:15:19 2018        (r329878)
@@ -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());
 }
 

Modified: head/sys/dev/random/nehemiah.c
==============================================================================
--- head/sys/dev/random/nehemiah.c      Fri Feb 23 20:01:42 2018        
(r329877)
+++ head/sys/dev/random/nehemiah.c      Fri Feb 23 20:15:19 2018        
(r329878)
@@ -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);
 }

Modified: head/sys/i386/i386/npx.c
==============================================================================
--- head/sys/i386/i386/npx.c    Fri Feb 23 20:01:42 2018        (r329877)
+++ head/sys/i386/i386/npx.c    Fri Feb 23 20:15:19 2018        (r329878)
@@ -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 
 
        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 
        pcb->pcb_save = fpu_kern_ctx_savefpu(ctx);
        pcb->pcb_flags |= PCB_KERNNPX;
        pcb->pcb_flags &= ~PCB_NPXINITDONE;
-       return (0);
+       return;
 }
 
 int

Modified: head/sys/i386/include/npx.h
==============================================================================
--- head/sys/i386/include/npx.h Fri Feb 23 20:01:42 2018        (r329877)
+++ head/sys/i386/include/npx.h Fri Feb 23 20:15:19 2018        (r329878)
@@ -76,7 +76,7 @@ void  npx_set_fpregs_xmm(struct save87 *, struct savexm
 
 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);
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to