diff --git a/sys/amd64/amd64/mem.c b/sys/amd64/amd64/mem.c --- a/sys/amd64/amd64/mem.c +++ b/sys/amd64/amd64/mem.c @@ -79,6 +79,7 @@ struct iovec *iov; void *p; ssize_t orig_resid; + vm_prot_t prot; u_long v, vd; u_int c; int error; @@ -110,8 +111,16 @@ break; } - if (!kernacc((void *)v, c, uio->uio_rw == UIO_READ ? - VM_PROT_READ : VM_PROT_WRITE)) { + switch (uio->uio_rw) { + case UIO_READ: + prot = VM_PROT_READ; + break; + case UIO_WRITE: + prot = VM_PROT_WRITE; + break; + } + + if (!kernacc((void *)v, c, prot)) { error = EFAULT; break; } diff --git a/sys/amd64/amd64/uio_machdep.c b/sys/amd64/amd64/uio_machdep.c --- a/sys/amd64/amd64/uio_machdep.c +++ b/sys/amd64/amd64/uio_machdep.c @@ -97,18 +97,26 @@ switch (uio->uio_segflg) { case UIO_USERSPACE: maybe_yield(); - if (uio->uio_rw == UIO_READ) + switch (uio->uio_rw) { + case UIO_READ: error = copyout(cp, iov->iov_base, cnt); - else + break; + case UIO_WRITE: error = copyin(iov->iov_base, cp, cnt); + break; + } if (error) goto out; break; case UIO_SYSSPACE: - if (uio->uio_rw == UIO_READ) + switch (uio->uio_rw) { + case UIO_READ: bcopy(cp, iov->iov_base, cnt); - else + break; + case UIO_WRITE: bcopy(iov->iov_base, cp, cnt); + break; + } break; case UIO_NOCOPY: break; diff --git a/sys/arm/arm/uio_machdep.c b/sys/arm/arm/uio_machdep.c --- a/sys/arm/arm/uio_machdep.c +++ b/sys/arm/arm/uio_machdep.c @@ -94,20 +94,28 @@ switch (uio->uio_segflg) { case UIO_USERSPACE: maybe_yield(); - if (uio->uio_rw == UIO_READ) + switch (uio->uio_rw) { + case UIO_READ: error = copyout(cp, iov->iov_base, cnt); - else + break; + case UIO_WRITE: error = copyin(iov->iov_base, cp, cnt); + break; + } if (error) { sf_buf_free(sf); goto out; } break; case UIO_SYSSPACE: - if (uio->uio_rw == UIO_READ) + switch (uio->uio_rw) { + case UIO_READ: bcopy(cp, iov->iov_base, cnt); - else + break; + case UIO_WRITE: bcopy(iov->iov_base, cp, cnt); + break; + } break; case UIO_NOCOPY: break; diff --git a/sys/arm64/arm64/mem.c b/sys/arm64/arm64/mem.c --- a/sys/arm64/arm64/mem.c +++ b/sys/arm64/arm64/mem.c @@ -49,6 +49,7 @@ struct vm_page m; vm_page_t marr; vm_offset_t off, v; + vm_prot_t prot; u_int cnt; int error; @@ -78,8 +79,16 @@ break; } - if (!kernacc((void *)v, cnt, uio->uio_rw == UIO_READ ? - VM_PROT_READ : VM_PROT_WRITE)) { + switch (uio->uio_rw) { + case UIO_READ: + prot = VM_PROT_READ; + break; + case UIO_WRITE: + prot = VM_PROT_WRITE; + break; + } + + if (!kernacc((void *)v, cnt, prot)) { error = EFAULT; break; } diff --git a/sys/arm64/arm64/uio_machdep.c b/sys/arm64/arm64/uio_machdep.c --- a/sys/arm64/arm64/uio_machdep.c +++ b/sys/arm64/arm64/uio_machdep.c @@ -95,18 +95,26 @@ switch (uio->uio_segflg) { case UIO_USERSPACE: maybe_yield(); - if (uio->uio_rw == UIO_READ) + switch (uio->uio_rw) { + case UIO_READ: error = copyout(cp, iov->iov_base, cnt); - else + break; + case UIO_WRITE: error = copyin(iov->iov_base, cp, cnt); + break; + } if (error) goto out; break; case UIO_SYSSPACE: - if (uio->uio_rw == UIO_READ) + switch (uio->uio_rw) { + case UIO_READ: bcopy(cp, iov->iov_base, cnt); - else + break; + case UIO_WRITE: bcopy(iov->iov_base, cp, cnt); + break; + } break; case UIO_NOCOPY: break; diff --git a/sys/compat/lindebugfs/lindebugfs.c b/sys/compat/lindebugfs/lindebugfs.c --- a/sys/compat/lindebugfs/lindebugfs.c +++ b/sys/compat/lindebugfs/lindebugfs.c @@ -136,19 +136,28 @@ } rc = -ENODEV; - if (uio->uio_rw == UIO_READ && d->dm_fops->read) { - rc = -ENOMEM; - buf = (char *) malloc(sb->s_size, M_DFSINT, M_ZERO | M_NOWAIT); - if (buf != NULL) { - rc = d->dm_fops->read(&lf, buf, sb->s_size, &off); - if (rc > 0) - sbuf_bcpy(sb, buf, strlen(buf)); + switch (uio->uio_rw) { + case UIO_READ: + if (d->dm_fops->read != NULL) { + rc = -ENOMEM; + buf = malloc(sb->s_size, M_DFSINT, M_ZERO | M_NOWAIT); + if (buf != NULL) { + rc = d->dm_fops->read(&lf, buf, sb->s_size, + &off); + if (rc > 0) + sbuf_bcpy(sb, buf, strlen(buf)); - free(buf, M_DFSINT); + free(buf, M_DFSINT); + } } - } else if (uio->uio_rw == UIO_WRITE && d->dm_fops->write) { - sbuf_finish(sb); - rc = d->dm_fops->write(&lf, sbuf_data(sb), sbuf_len(sb), &off); + break; + case UIO_WRITE: + if (d->dm_fops->write != NULL) { + sbuf_finish(sb); + rc = d->dm_fops->write(&lf, sbuf_data(sb), sbuf_len(sb), + &off); + } + break; } if (d->dm_fops->release) diff --git a/sys/dev/iicbus/iic.c b/sys/dev/iicbus/iic.c --- a/sys/dev/iicbus/iic.c +++ b/sys/dev/iicbus/iic.c @@ -239,7 +239,8 @@ num_bytes = MIN(uio->uio_resid, sizeof(buffer)); transferred_bytes = 0; - if (uio->uio_rw == UIO_WRITE) { + switch (uio->uio_rw) { + case UIO_WRITE: error = uiomove(buffer, num_bytes, uio); while ((error == 0) && (transferred_bytes < num_bytes)) { @@ -248,13 +249,14 @@ num_bytes - transferred_bytes, &written_bytes, 0); transferred_bytes += written_bytes; } - - } else if (uio->uio_rw == UIO_READ) { + break; + case UIO_READ: error = iicbus_read(parent, buffer, num_bytes, &transferred_bytes, ((uio->uio_resid <= sizeof(buffer)) ? last : 0), 0); if (error == 0) error = uiomove(buffer, transferred_bytes, uio); + break; } } @@ -290,10 +292,14 @@ return (error); } - if (uio->uio_rw == UIO_READ) + switch (uio->uio_rw) { + case UIO_READ: addr = priv->addr | LSB; - else + break; + case UIO_WRITE: addr = priv->addr & ~LSB; + break; + } error = iicbus_start(parent, addr, 0); if (error != 0) diff --git a/sys/dev/md/md.c b/sys/dev/md/md.c --- a/sys/dev/md/md.c +++ b/sys/dev/md/md.c @@ -981,11 +981,13 @@ auio.uio_iovcnt = 1; } iostart = auio.uio_offset; - if (auio.uio_rw == UIO_READ) { + switch (auio.uio_rw) { + case UIO_READ: vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); error = VOP_READ(vp, &auio, 0, sc->cred); VOP_UNLOCK(vp); - } else { + break; + case UIO_WRITE: (void) vn_start_write(vp, &mp, V_WAIT); vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); error = VOP_WRITE(vp, &auio, sc->flags & MD_ASYNC ? 0 : IO_SYNC, @@ -994,6 +996,7 @@ vn_finished_write(mp); if (error == 0) sc->flags &= ~MD_VERIFY; + break; } /* When MD_CACHE is set, try to avoid double-caching the data. */ diff --git a/sys/fs/procfs/procfs_osrel.c b/sys/fs/procfs/procfs_osrel.c --- a/sys/fs/procfs/procfs_osrel.c +++ b/sys/fs/procfs/procfs_osrel.c @@ -45,9 +45,11 @@ if (uio == NULL) return (EOPNOTSUPP); - if (uio->uio_rw == UIO_READ) { + switch (uio->uio_rw) { + case UIO_READ: sbuf_printf(sb, "%d\n", p->p_osrel); - } else { + break; + case UIO_WRITE: sbuf_trim(sb); sbuf_finish(sb); pp = sbuf_data(sb); @@ -62,6 +64,7 @@ osrel = ov; } p->p_osrel = osrel; + break; } return (0); } diff --git a/sys/i386/i386/uio_machdep.c b/sys/i386/i386/uio_machdep.c --- a/sys/i386/i386/uio_machdep.c +++ b/sys/i386/i386/uio_machdep.c @@ -94,10 +94,14 @@ switch (uio->uio_segflg) { case UIO_USERSPACE: maybe_yield(); - if (uio->uio_rw == UIO_READ) + switch (uio->uio_rw) { + case UIO_READ: error = copyout(cp, iov->iov_base, cnt); - else + break; + case UIO_WRITE: error = copyin(iov->iov_base, cp, cnt); + break; + } if (error) { sf_buf_free(sf); sched_unpin(); @@ -105,10 +109,14 @@ } break; case UIO_SYSSPACE: - if (uio->uio_rw == UIO_READ) + switch (uio->uio_rw) { + case UIO_READ: bcopy(cp, iov->iov_base, cnt); - else + break; + case UIO_WRITE: bcopy(iov->iov_base, cp, cnt); + break; + } break; case UIO_NOCOPY: break; diff --git a/sys/kern/kern_physio.c b/sys/kern/kern_physio.c --- a/sys/kern/kern_physio.c +++ b/sys/kern/kern_physio.c @@ -116,14 +116,17 @@ #ifdef RACCT if (racct_enable) { PROC_LOCK(curproc); - if (uio->uio_rw == UIO_READ) { + switch (uio->uio_rw) { + case UIO_READ: racct_add_force(curproc, RACCT_READBPS, uio->uio_iov[i].iov_len); racct_add_force(curproc, RACCT_READIOPS, 1); - } else { + break; + case UIO_WRITE: racct_add_force(curproc, RACCT_WRITEBPS, uio->uio_iov[i].iov_len); racct_add_force(curproc, RACCT_WRITEIOPS, 1); + break; } PROC_UNLOCK(curproc); } @@ -131,12 +134,15 @@ while (uio->uio_iov[i].iov_len) { g_reset_bio(bp); - if (uio->uio_rw == UIO_READ) { + switch (uio->uio_rw) { + case UIO_READ: bp->bio_cmd = BIO_READ; curthread->td_ru.ru_inblock++; - } else { + break; + case UIO_WRITE: bp->bio_cmd = BIO_WRITE; curthread->td_ru.ru_oublock++; + break; } bp->bio_offset = uio->uio_offset; base = uio->uio_iov[i].iov_base; diff --git a/sys/kern/subr_uio.c b/sys/kern/subr_uio.c --- a/sys/kern/subr_uio.c +++ b/sys/kern/subr_uio.c @@ -249,19 +249,27 @@ switch (uio->uio_segflg) { case UIO_USERSPACE: maybe_yield(); - if (uio->uio_rw == UIO_READ) + switch (uio->uio_rw) { + case UIO_READ: error = copyout(cp, iov->iov_base, cnt); - else + break; + case UIO_WRITE: error = copyin(iov->iov_base, cp, cnt); + break; + } if (error) goto out; break; case UIO_SYSSPACE: - if (uio->uio_rw == UIO_READ) + switch (uio->uio_rw) { + case UIO_READ: bcopy(cp, iov->iov_base, cnt); - else + break; + case UIO_WRITE: bcopy(iov->iov_base, cp, cnt); + break; + } break; case UIO_NOCOPY: break; diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c --- a/sys/kern/vfs_vnops.c +++ b/sys/kern/vfs_vnops.c @@ -1259,12 +1259,15 @@ uio, args->cred, args->flags, td); break; case VN_IO_FAULT_VOP: - if (uio->uio_rw == UIO_READ) { + switch (uio->uio_rw) { + case UIO_READ: error = VOP_READ(args->args.vop_args.vp, uio, args->flags, args->cred); - } else if (uio->uio_rw == UIO_WRITE) { + break; + case UIO_WRITE: error = VOP_WRITE(args->args.vop_args.vp, uio, args->flags, args->cred); + break; } break; default: diff --git a/sys/powerpc/powerpc/uio_machdep.c b/sys/powerpc/powerpc/uio_machdep.c --- a/sys/powerpc/powerpc/uio_machdep.c +++ b/sys/powerpc/powerpc/uio_machdep.c @@ -100,20 +100,28 @@ switch (uio->uio_segflg) { case UIO_USERSPACE: maybe_yield(); - if (uio->uio_rw == UIO_READ) + switch (uio->uio_rw) { + case UIO_READ: error = copyout(cp, iov->iov_base, cnt); - else + break; + case UIO_WRITE: error = copyin(iov->iov_base, cp, cnt); + break; + } if (error) { sf_buf_free(sf); goto out; } break; case UIO_SYSSPACE: - if (uio->uio_rw == UIO_READ) + switch (uio->uio_rw) { + case UIO_READ: bcopy(cp, iov->iov_base, cnt); - else + break; + case UIO_WRITE: bcopy(iov->iov_base, cp, cnt); + break; + } break; case UIO_NOCOPY: break; diff --git a/sys/riscv/riscv/mem.c b/sys/riscv/riscv/mem.c --- a/sys/riscv/riscv/mem.c +++ b/sys/riscv/riscv/mem.c @@ -50,6 +50,7 @@ struct iovec *iov; struct vm_page m; vm_page_t marr; + vm_prot_t prot; u_int cnt; int error; @@ -79,8 +80,16 @@ break; } - if (!kernacc((void *)v, cnt, uio->uio_rw == UIO_READ ? - VM_PROT_READ : VM_PROT_WRITE)) { + switch (uio->uio_rw) { + case UIO_READ: + prot = VM_PROT_READ; + break; + case UIO_WRITE: + prot = VM_PROT_WRITE; + break; + } + + if (!kernacc((void *)v, cnt, prot)) { error = EFAULT; break; } diff --git a/sys/riscv/riscv/uio_machdep.c b/sys/riscv/riscv/uio_machdep.c --- a/sys/riscv/riscv/uio_machdep.c +++ b/sys/riscv/riscv/uio_machdep.c @@ -95,18 +95,26 @@ switch (uio->uio_segflg) { case UIO_USERSPACE: maybe_yield(); - if (uio->uio_rw == UIO_READ) + switch (uio->uio_rw) { + case UIO_READ: error = copyout(cp, iov->iov_base, cnt); - else + break; + case UIO_WRITE: error = copyin(iov->iov_base, cp, cnt); + break; + } if (error) goto out; break; case UIO_SYSSPACE: - if (uio->uio_rw == UIO_READ) + switch (uio->uio_rw) { + case UIO_READ: bcopy(cp, iov->iov_base, cnt); - else + break; + case UIO_WRITE: bcopy(iov->iov_base, cp, cnt); + break; + } break; case UIO_NOCOPY: break; diff --git a/sys/ufs/ffs/ffs_suspend.c b/sys/ufs/ffs/ffs_suspend.c --- a/sys/ufs/ffs/ffs_suspend.c +++ b/sys/ufs/ffs/ffs_suspend.c @@ -138,7 +138,8 @@ NOCRED, &bp); if (error != 0) goto out; - if (uio->uio_rw == UIO_WRITE) { + switch (uio->uio_rw) { + case UIO_WRITE: error = copyin(base, bp->b_data, len); if (error != 0) { bp->b_flags |= B_INVAL | B_NOCACHE; @@ -148,11 +149,13 @@ error = bwrite(bp); if (error != 0) goto out; - } else { + break; + case UIO_READ: error = copyout(bp->b_data, base, len); brelse(bp); if (error != 0) goto out; + break; } uio->uio_iov[i].iov_base = (char *)uio->uio_iov[i].iov_base + len;