Date: Sat, 15 Nov 2008 12:35:52 GMT From: Hans Petter Selasky <hselasky@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 153005 for review Message-ID: <200811151235.mAFCZqLN028933@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=153005 Change 153005 by hselasky@hselasky_laptop001 on 2008/11/15 12:35:35 Fix a minor bug where the FIFO index was used instead of the endpoint index. Affected files ... .. //depot/projects/usb/src/sys/dev/usb2/core/usb2_core.h#25 edit .. //depot/projects/usb/src/sys/dev/usb2/core/usb2_dev.c#41 edit Differences ... ==== //depot/projects/usb/src/sys/dev/usb2/core/usb2_core.h#25 (text+ko) ==== @@ -404,7 +404,7 @@ uint16_t bus_index; /* bus index */ uint8_t dev_index; /* device index */ uint8_t iface_index; /* interface index */ - uint8_t ep_index; /* endpoint index */ + uint8_t fifo_index; /* FIFO index */ uint8_t is_read; /* set if location has read access */ uint8_t is_write; /* set if location has write access */ uint8_t is_uref; /* set if USB refcount decr. needed */ ==== //depot/projects/usb/src/sys/dev/usb2/core/usb2_dev.c#41 (text+ko) ==== @@ -465,6 +465,7 @@ struct usb2_fifo *f; int fflags; uint8_t need_uref; + uint8_t dev_ep_index; if (fp) { /* check if we need uref hint */ @@ -496,7 +497,7 @@ ploc->dev_index = (devloc / USB_BUS_MAX) % USB_DEV_MAX; ploc->iface_index = (devloc / (USB_BUS_MAX * USB_DEV_MAX)) % USB_IFACE_MAX; - ploc->ep_index = (devloc / (USB_BUS_MAX * USB_DEV_MAX * + ploc->fifo_index = (devloc / (USB_BUS_MAX * USB_DEV_MAX * USB_IFACE_MAX)); mtx_lock(&usb2_ref_lock); @@ -518,18 +519,6 @@ DPRINTFN(2, "no dev ref\n"); goto error; } - ploc->iface = usb2_get_iface(ploc->udev, ploc->iface_index); - if (ploc->ep_index != 0) { - /* non control endpoint - we need an interface */ - if (ploc->iface == NULL) { - DPRINTFN(2, "no iface\n"); - goto error; - } - if (ploc->iface->idesc == NULL) { - DPRINTFN(2, "no idesc\n"); - goto error; - } - } /* check if we are doing an open */ if (fp == NULL) { /* set defaults */ @@ -538,14 +527,17 @@ ploc->is_write = 0; ploc->is_read = 0; ploc->is_usbfs = 0; + /* NOTE: variable overloading: */ + dev_ep_index = ploc->fifo_index; } else { /* initialise "is_usbfs" flag */ ploc->is_usbfs = 0; + dev_ep_index = 255; /* dummy */ /* check for write */ if (fflags & FWRITE) { ppf = ploc->udev->fifo; - f = ppf[ploc->ep_index + USB_FIFO_TX]; + f = ppf[ploc->fifo_index + USB_FIFO_TX]; ploc->txfifo = f; ploc->is_write = 1; /* ref */ if ((f == NULL) || @@ -557,6 +549,11 @@ if (f->fs_ep_max != 0) { ploc->is_usbfs = 1; } + /* + * Get real endpoint index associated with + * this FIFO: + */ + dev_ep_index = f->dev_ep_index; } else { ploc->txfifo = NULL; ploc->is_write = 0; /* no ref */ @@ -565,7 +562,7 @@ /* check for read */ if (fflags & FREAD) { ppf = ploc->udev->fifo; - f = ppf[ploc->ep_index + USB_FIFO_RX]; + f = ppf[ploc->fifo_index + USB_FIFO_RX]; ploc->rxfifo = f; ploc->is_read = 1; /* ref */ if ((f == NULL) || @@ -577,12 +574,30 @@ if (f->fs_ep_max != 0) { ploc->is_usbfs = 1; } + /* + * Get real endpoint index associated with + * this FIFO: + */ + dev_ep_index = f->dev_ep_index; } else { ploc->rxfifo = NULL; ploc->is_read = 0; /* no ref */ } } + /* check if we require an interface */ + ploc->iface = usb2_get_iface(ploc->udev, ploc->iface_index); + if (dev_ep_index != 0) { + /* non control endpoint - we need an interface */ + if (ploc->iface == NULL) { + DPRINTFN(2, "no iface\n"); + goto error; + } + if (ploc->iface->idesc == NULL) { + DPRINTFN(2, "no idesc\n"); + goto error; + } + } /* when everything is OK we increment the refcounts */ if (ploc->is_write) { DPRINTFN(2, "ref write\n"); @@ -684,7 +699,9 @@ struct usb2_fifo *f; struct usb2_pipe *pipe; uint8_t iface_index = ploc->iface_index; - uint8_t dev_ep_index = ploc->ep_index; + + /* NOTE: variable overloading: */ + uint8_t dev_ep_index = ploc->fifo_index; uint8_t n; uint8_t is_tx; uint8_t is_rx; @@ -1125,15 +1142,23 @@ struct usb2_interface *iface; int err; - iface = usb2_get_iface(udev, iface_index); - if (iface == NULL) { - return (EINVAL); + if (ep_index != 0) { + /* + * Non-control endpoints are always + * associated with an interface: + */ + iface = usb2_get_iface(udev, iface_index); + if (iface == NULL) { + return (EINVAL); + } + if (iface->idesc == NULL) { + return (EINVAL); + } + } else { + iface = NULL; } - if (iface->idesc == NULL) { - return (EINVAL); - } /* scan down the permissions tree */ - if ((ep_index != 0) && iface && + if ((iface != NULL) && (usb2_check_access(fflags, &iface->perm) == 0)) { /* we got access through the interface */ err = 0; @@ -1210,8 +1235,14 @@ DPRINTFN(2, "cannot ref device\n"); return (ENXIO); } + /* + * NOTE: Variable overloading. "usb2_fifo_create" will update + * the FIFO index. Right here we can assume that the + * "fifo_index" is the same like the endpoint number without + * direction mask, if the "fifo_index" is less than 16. + */ err = usb2_check_thread_perm(loc.udev, td, fflags, - loc.iface_index, loc.ep_index); + loc.iface_index, loc.fifo_index); /* check for error */ if (err) {
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200811151235.mAFCZqLN028933>