diff options
author | Stefan Kempf <stefan@cvs.openbsd.org> | 2016-03-03 18:13:25 +0000 |
---|---|---|
committer | Stefan Kempf <stefan@cvs.openbsd.org> | 2016-03-03 18:13:25 +0000 |
commit | 9c19b666cfe9ef6055f9a2557d25b4c26400ad48 (patch) | |
tree | 18227add2d3f88080cde8722ebcd0d539b60c9d4 /sys | |
parent | 5da9549d30ca9c35388416cdcd4c3d585656def2 (diff) |
Convert uiomovei to uiomove. Fixes a few integer truncations along the
way.
ok natano@
Diffstat (limited to 'sys')
-rw-r--r-- | sys/dev/usb/ugen.c | 53 | ||||
-rw-r--r-- | sys/dev/usb/uhid.c | 10 | ||||
-rw-r--r-- | sys/dev/usb/ulpt.c | 10 | ||||
-rw-r--r-- | sys/dev/usb/usb.c | 17 | ||||
-rw-r--r-- | sys/dev/usb/usb_subr.c | 10 | ||||
-rw-r--r-- | sys/dev/usb/usbdi.h | 4 |
6 files changed, 53 insertions, 51 deletions
diff --git a/sys/dev/usb/ugen.c b/sys/dev/usb/ugen.c index 45a207edae3..12eae3f9af3 100644 --- a/sys/dev/usb/ugen.c +++ b/sys/dev/usb/ugen.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ugen.c,v 1.91 2015/10/19 14:05:01 mpi Exp $ */ +/* $OpenBSD: ugen.c,v 1.92 2016/03/03 18:13:24 stefan Exp $ */ /* $NetBSD: ugen.c,v 1.63 2002/11/26 18:49:48 christos Exp $ */ /* $FreeBSD: src/sys/dev/usb/ugen.c,v 1.26 1999/11/17 22:33:41 n_hibma Exp $ */ @@ -468,7 +468,8 @@ int ugen_do_read(struct ugen_softc *sc, int endpt, struct uio *uio, int flag) { struct ugen_endpoint *sce = &sc->sc_endpoints[endpt][IN]; - u_int32_t n, tn; + u_int32_t tn; + size_t n; char buf[UGEN_BBSIZE]; struct usbd_xfer *xfer; usbd_status err; @@ -523,16 +524,16 @@ ugen_do_read(struct ugen_softc *sc, int endpt, struct uio *uio, int flag) /* Transfer as many chunks as possible. */ while (sce->q.c_cc > 0 && uio->uio_resid > 0 && !error) { - n = min(sce->q.c_cc, uio->uio_resid); + n = ulmin(sce->q.c_cc, uio->uio_resid); if (n > sizeof(buffer)) n = sizeof(buffer); /* Remove a small chunk from the input queue. */ q_to_b(&sce->q, buffer, n); - DPRINTFN(5, ("ugenread: got %d chars\n", n)); + DPRINTFN(5, ("ugenread: got %zu chars\n", n)); /* Copy the data to the user process. */ - error = uiomovei(buffer, n, uio); + error = uiomove(buffer, n, uio); if (error) break; } @@ -546,8 +547,8 @@ ugen_do_read(struct ugen_softc *sc, int endpt, struct uio *uio, int flag) flags |= USBD_SHORT_XFER_OK; if (sce->timeout == 0) flags |= USBD_CATCH; - while ((n = min(UGEN_BBSIZE, uio->uio_resid)) != 0) { - DPRINTFN(1, ("ugenread: start transfer %d bytes\n",n)); + while ((n = ulmin(UGEN_BBSIZE, uio->uio_resid)) != 0) { + DPRINTFN(1, ("ugenread: start transfer %zu bytes\n",n)); usbd_setup_xfer(xfer, sce->pipeh, 0, buf, n, flags, sce->timeout, NULL); err = usbd_transfer(xfer); @@ -562,8 +563,8 @@ ugen_do_read(struct ugen_softc *sc, int endpt, struct uio *uio, int flag) break; } usbd_get_xfer_status(xfer, NULL, NULL, &tn, NULL); - DPRINTFN(1, ("ugenread: got %d bytes\n", tn)); - error = uiomovei(buf, tn, uio); + DPRINTFN(1, ("ugenread: got %u bytes\n", tn)); + error = uiomove(buf, tn, uio); if (error || tn < n) break; } @@ -594,14 +595,14 @@ ugen_do_read(struct ugen_softc *sc, int endpt, struct uio *uio, int flag) while (sce->cur != sce->fill && uio->uio_resid > 0 && !error) { if(sce->fill > sce->cur) - n = min(sce->fill - sce->cur, uio->uio_resid); + n = ulmin(sce->fill - sce->cur, uio->uio_resid); else - n = min(sce->limit - sce->cur, uio->uio_resid); + n = ulmin(sce->limit - sce->cur, uio->uio_resid); - DPRINTFN(5, ("ugenread: isoc got %d chars\n", n)); + DPRINTFN(5, ("ugenread: isoc got %zu chars\n", n)); /* Copy the data to the user process. */ - error = uiomovei(sce->cur, n, uio); + error = uiomove(sce->cur, n, uio); if (error) break; sce->cur += n; @@ -638,7 +639,7 @@ int ugen_do_write(struct ugen_softc *sc, int endpt, struct uio *uio, int flag) { struct ugen_endpoint *sce = &sc->sc_endpoints[endpt][OUT]; - u_int32_t n; + size_t n; int flags, error = 0; char buf[UGEN_BBSIZE]; struct usbd_xfer *xfer; @@ -671,11 +672,11 @@ ugen_do_write(struct ugen_softc *sc, int endpt, struct uio *uio, int flag) xfer = usbd_alloc_xfer(sc->sc_udev); if (xfer == 0) return (EIO); - while ((n = min(UGEN_BBSIZE, uio->uio_resid)) != 0) { - error = uiomovei(buf, n, uio); + while ((n = ulmin(UGEN_BBSIZE, uio->uio_resid)) != 0) { + error = uiomove(buf, n, uio); if (error) break; - DPRINTFN(1, ("ugenwrite: transfer %d bytes\n", n)); + DPRINTFN(1, ("ugenwrite: transfer %zu bytes\n", n)); usbd_setup_xfer(xfer, sce->pipeh, 0, buf, n, flags, sce->timeout, NULL); err = usbd_transfer(xfer); @@ -696,12 +697,12 @@ ugen_do_write(struct ugen_softc *sc, int endpt, struct uio *uio, int flag) xfer = usbd_alloc_xfer(sc->sc_udev); if (xfer == 0) return (EIO); - while ((n = min(UGETW(sce->edesc->wMaxPacketSize), + while ((n = ulmin(UGETW(sce->edesc->wMaxPacketSize), uio->uio_resid)) != 0) { - error = uiomovei(buf, n, uio); + error = uiomove(buf, n, uio); if (error) break; - DPRINTFN(1, ("ugenwrite: transfer %d bytes\n", n)); + DPRINTFN(1, ("ugenwrite: transfer %zu bytes\n", n)); usbd_setup_xfer(xfer, sce->pipeh, 0, buf, n, flags, sce->timeout, NULL); err = usbd_transfer(xfer); @@ -1106,7 +1107,7 @@ ugen_do_ioctl(struct ugen_softc *sc, int endpt, u_long cmd, caddr_t addr, break; case USB_GET_FULL_DESC: { - int len; + u_int len; struct iovec iov; struct uio uio; struct usb_full_desc *fd = (struct usb_full_desc *)addr; @@ -1126,7 +1127,7 @@ ugen_do_ioctl(struct ugen_softc *sc, int endpt, u_long cmd, caddr_t addr, uio.uio_segflg = UIO_USERSPACE; uio.uio_rw = UIO_READ; uio.uio_procp = p; - error = uiomovei((void *)cdesc, len, &uio); + error = uiomove((void *)cdesc, len, &uio); free(cdesc, M_TEMP, 0); return (error); } @@ -1143,7 +1144,7 @@ ugen_do_ioctl(struct ugen_softc *sc, int endpt, u_long cmd, caddr_t addr, case USB_DO_REQUEST: { struct usb_ctl_request *ur = (void *)addr; - int len = UGETW(ur->ucr_request.wLength); + size_t len = UGETW(ur->ucr_request.wLength); struct iovec iov; struct uio uio; void *ptr = 0; @@ -1160,7 +1161,7 @@ ugen_do_ioctl(struct ugen_softc *sc, int endpt, u_long cmd, caddr_t addr, ur->ucr_request.bRequest == UR_SET_INTERFACE)) return (EINVAL); - if (len < 0 || len > 32767) + if (len > 32767) return (EINVAL); if (len != 0) { iov.iov_base = (caddr_t)ur->ucr_data; @@ -1176,7 +1177,7 @@ ugen_do_ioctl(struct ugen_softc *sc, int endpt, u_long cmd, caddr_t addr, uio.uio_procp = p; ptr = malloc(len, M_TEMP, M_WAITOK); if (uio.uio_rw == UIO_WRITE) { - error = uiomovei(ptr, len, &uio); + error = uiomove(ptr, len, &uio); if (error) goto ret; } @@ -1193,7 +1194,7 @@ ugen_do_ioctl(struct ugen_softc *sc, int endpt, u_long cmd, caddr_t addr, len = ur->ucr_actlen; if (len != 0) { if (uio.uio_rw == UIO_READ) { - error = uiomovei(ptr, len, &uio); + error = uiomove(ptr, len, &uio); if (error) goto ret; } diff --git a/sys/dev/usb/uhid.c b/sys/dev/usb/uhid.c index e1ad7d026c8..0aebcd7a5dd 100644 --- a/sys/dev/usb/uhid.c +++ b/sys/dev/usb/uhid.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uhid.c,v 1.64 2016/02/28 17:57:50 stefan Exp $ */ +/* $OpenBSD: uhid.c,v 1.65 2016/03/03 18:13:24 stefan Exp $ */ /* $NetBSD: uhid.c,v 1.57 2003/03/11 16:44:00 augustss Exp $ */ /* @@ -281,16 +281,16 @@ uhid_do_read(struct uhid_softc *sc, struct uio *uio, int flag) /* Transfer as many chunks as possible. */ while (sc->sc_q.c_cc > 0 && uio->uio_resid > 0 && !error) { - length = min(sc->sc_q.c_cc, uio->uio_resid); + length = ulmin(sc->sc_q.c_cc, uio->uio_resid); if (length > sizeof(buffer)) length = sizeof(buffer); /* Remove a small chunk from the input queue. */ (void) q_to_b(&sc->sc_q, buffer, length); - DPRINTFN(5, ("uhidread: got %lu chars\n", (u_long)length)); + DPRINTFN(5, ("uhidread: got %zu chars\n", length)); /* Copy the data to the user process. */ - if ((error = uiomovei(buffer, length, uio)) != 0) + if ((error = uiomove(buffer, length, uio)) != 0) break; } @@ -327,7 +327,7 @@ uhid_do_write(struct uhid_softc *sc, struct uio *uio, int flag) error = 0; if (uio->uio_resid != size) return (EINVAL); - error = uiomovei(sc->sc_obuf, size, uio); + error = uiomove(sc->sc_obuf, size, uio); if (!error) { if (uhidev_set_report(sc->sc_hdev.sc_parent, UHID_OUTPUT_REPORT, sc->sc_hdev.sc_report_id, sc->sc_obuf, diff --git a/sys/dev/usb/ulpt.c b/sys/dev/usb/ulpt.c index cbf9d5e1d9b..5e036463311 100644 --- a/sys/dev/usb/ulpt.c +++ b/sys/dev/usb/ulpt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ulpt.c,v 1.52 2015/12/11 16:07:02 mpi Exp $ */ +/* $OpenBSD: ulpt.c,v 1.53 2016/03/03 18:13:24 stefan Exp $ */ /* $NetBSD: ulpt.c,v 1.57 2003/01/05 10:19:42 scw Exp $ */ /* $FreeBSD: src/sys/dev/usb/ulpt.c,v 1.24 1999/11/17 22:33:44 n_hibma Exp $ */ @@ -601,7 +601,7 @@ ulptclose(dev_t dev, int flag, int mode, struct proc *p) int ulpt_do_write(struct ulpt_softc *sc, struct uio *uio, int flags) { - u_int32_t n; + size_t n; int error = 0; void *bufp; struct usbd_xfer *xfer; @@ -616,12 +616,12 @@ ulpt_do_write(struct ulpt_softc *sc, struct uio *uio, int flags) usbd_free_xfer(xfer); return (ENOMEM); } - while ((n = min(ULPT_BSIZE, uio->uio_resid)) != 0) { + while ((n = ulmin(ULPT_BSIZE, uio->uio_resid)) != 0) { ulpt_statusmsg(ulpt_status(sc), sc); - error = uiomovei(bufp, n, uio); + error = uiomove(bufp, n, uio); if (error) break; - DPRINTFN(1, ("ulptwrite: transfer %d bytes\n", n)); + DPRINTFN(1, ("ulptwrite: transfer %zu bytes\n", n)); usbd_setup_xfer(xfer, sc->sc_out_pipe, 0, bufp, n, USBD_NO_COPY | USBD_SYNCHRONOUS | USBD_CATCH, 0, NULL); err = usbd_transfer(xfer); diff --git a/sys/dev/usb/usb.c b/sys/dev/usb/usb.c index 7f991591620..732ecfdbb27 100644 --- a/sys/dev/usb/usb.c +++ b/sys/dev/usb/usb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: usb.c,v 1.109 2016/01/22 13:31:47 bluhm Exp $ */ +/* $OpenBSD: usb.c,v 1.110 2016/03/03 18:13:24 stefan Exp $ */ /* $NetBSD: usb.c,v 1.77 2003/01/01 00:10:26 thorpej Exp $ */ /* @@ -610,7 +610,7 @@ usbioctl(dev_t devt, u_long cmd, caddr_t data, int flag, struct proc *p) case USB_REQUEST: { struct usb_ctl_request *ur = (void *)data; - int len = UGETW(ur->ucr_request.wLength); + size_t len = UGETW(ur->ucr_request.wLength); struct iovec iov; struct uio uio; void *ptr = 0; @@ -621,7 +621,7 @@ usbioctl(dev_t devt, u_long cmd, caddr_t data, int flag, struct proc *p) if (!(flag & FWRITE)) return (EBADF); - DPRINTF(("usbioctl: USB_REQUEST addr=%d len=%d\n", addr, len)); + DPRINTF(("usbioctl: USB_REQUEST addr=%d len=%zu\n", addr, len)); /* Avoid requests that would damage the bus integrity. */ if ((ur->ucr_request.bmRequestType == UT_WRITE_DEVICE && ur->ucr_request.bRequest == UR_SET_ADDRESS) || @@ -631,7 +631,7 @@ usbioctl(dev_t devt, u_long cmd, caddr_t data, int flag, struct proc *p) ur->ucr_request.bRequest == UR_SET_INTERFACE)) return (EINVAL); - if (len < 0 || len > 32767) + if (len > 32767) return (EINVAL); if (addr < 0 || addr >= USB_MAX_DEVICES) return (EINVAL); @@ -651,7 +651,7 @@ usbioctl(dev_t devt, u_long cmd, caddr_t data, int flag, struct proc *p) uio.uio_procp = p; ptr = malloc(len, M_TEMP, M_WAITOK); if (uio.uio_rw == UIO_WRITE) { - error = uiomovei(ptr, len, &uio); + error = uiomove(ptr, len, &uio); if (error) goto ret; } @@ -668,7 +668,7 @@ usbioctl(dev_t devt, u_long cmd, caddr_t data, int flag, struct proc *p) len = ur->ucr_actlen; if (len != 0) { if (uio.uio_rw == UIO_READ) { - error = uiomovei(ptr, len, &uio); + error = uiomove(ptr, len, &uio); if (error) goto ret; } @@ -766,7 +766,8 @@ usbioctl(dev_t devt, u_long cmd, caddr_t data, int flag, struct proc *p) usb_config_descriptor_t *cdesc; struct iovec iov; struct uio uio; - int len, error; + size_t len; + int error; if (addr < 1 || addr >= USB_MAX_DEVICES) return (EINVAL); @@ -797,7 +798,7 @@ usbioctl(dev_t devt, u_long cmd, caddr_t data, int flag, struct proc *p) uio.uio_segflg = UIO_USERSPACE; uio.uio_rw = UIO_READ; uio.uio_procp = p; - error = uiomovei((void *)cdesc, len, &uio); + error = uiomove((void *)cdesc, len, &uio); free(cdesc, M_TEMP, 0); return (error); } diff --git a/sys/dev/usb/usb_subr.c b/sys/dev/usb/usb_subr.c index 2ffc97cb379..a255793ebae 100644 --- a/sys/dev/usb/usb_subr.c +++ b/sys/dev/usb/usb_subr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: usb_subr.c,v 1.119 2016/01/14 19:53:59 mpi Exp $ */ +/* $OpenBSD: usb_subr.c,v 1.120 2016/03/03 18:13:24 stefan Exp $ */ /* $NetBSD: usb_subr.c,v 1.103 2003/01/10 11:19:13 augustss Exp $ */ /* $FreeBSD: src/sys/dev/usb/usb_subr.c,v 1.18 1999/11/17 22:33:47 n_hibma Exp $ */ @@ -1310,10 +1310,10 @@ usbd_fill_deviceinfo(struct usbd_device *dev, struct usb_device_info *di, /* Retrieve a complete descriptor for a certain device and index. */ usb_config_descriptor_t * -usbd_get_cdesc(struct usbd_device *dev, int index, int *lenp) +usbd_get_cdesc(struct usbd_device *dev, int index, u_int *lenp) { usb_config_descriptor_t *cdesc, *tdesc, cdescr; - int len; + u_int len; usbd_status err; if (index == USB_CURRENT_CONFIG_INDEX) { @@ -1325,14 +1325,14 @@ usbd_get_cdesc(struct usbd_device *dev, int index, int *lenp) *lenp = len; cdesc = malloc(len, M_TEMP, M_WAITOK); memcpy(cdesc, tdesc, len); - DPRINTFN(5,("usbd_get_cdesc: current, len=%d\n", len)); + DPRINTFN(5,("usbd_get_cdesc: current, len=%u\n", len)); } else { err = usbd_get_desc(dev, UDESC_CONFIG, index, USB_CONFIG_DESCRIPTOR_SIZE, &cdescr); if (err || cdescr.bDescriptorType != UDESC_CONFIG) return (0); len = UGETW(cdescr.wTotalLength); - DPRINTFN(5,("usbd_get_cdesc: index=%d, len=%d\n", index, len)); + DPRINTFN(5,("usbd_get_cdesc: index=%d, len=%u\n", index, len)); if (lenp) *lenp = len; cdesc = malloc(len, M_TEMP, M_WAITOK); diff --git a/sys/dev/usb/usbdi.h b/sys/dev/usb/usbdi.h index cab3cdf3e23..2e85c9afe15 100644 --- a/sys/dev/usb/usbdi.h +++ b/sys/dev/usb/usbdi.h @@ -1,4 +1,4 @@ -/* $OpenBSD: usbdi.h,v 1.66 2015/07/10 15:47:48 mpi Exp $ */ +/* $OpenBSD: usbdi.h,v 1.67 2016/03/03 18:13:24 stefan Exp $ */ /* $NetBSD: usbdi.h,v 1.62 2002/07/11 21:14:35 augustss Exp $ */ /* $FreeBSD: src/sys/dev/usb/usbdi.h,v 1.18 1999/11/17 22:33:49 n_hibma Exp $ */ @@ -130,7 +130,7 @@ usb_device_descriptor_t *usbd_get_device_descriptor(struct usbd_device *dev); usbd_status usbd_set_interface(struct usbd_interface *, int); int usbd_get_no_alts(usb_config_descriptor_t *, int); void usbd_fill_deviceinfo(struct usbd_device *, struct usb_device_info *, int); -usb_config_descriptor_t *usbd_get_cdesc(struct usbd_device *, int, int *); +usb_config_descriptor_t *usbd_get_cdesc(struct usbd_device *, int, u_int *); int usbd_get_interface_altindex(struct usbd_interface *iface); usb_interface_descriptor_t *usbd_find_idesc(usb_config_descriptor_t *cd, |