PERFORCE change 144650 for review
Hans Petter Selasky
hselasky at FreeBSD.org
Fri Jul 4 18:32:14 UTC 2008
http://perforce.freebsd.org/chv.cgi?CH=144650
Change 144650 by hselasky at hselasky_laptop001 on 2008/07/04 18:31:55
Cleanup locking a little bit.
Affected files ...
.. //depot/projects/usb/src/sys/dev/usb2/core/usb2_device.c#11 edit
.. //depot/projects/usb/src/sys/dev/usb2/core/usb2_hub.c#10 edit
Differences ...
==== //depot/projects/usb/src/sys/dev/usb2/core/usb2_device.c#11 (text+ko) ====
@@ -507,15 +507,19 @@
uint16_t max_power;
uint8_t nifc;
uint8_t selfpowered;
+ uint8_t do_unlock;
usb2_error_t err;
DPRINTF(5, "udev=%p index=%d\n", udev, index);
- if (!sx_xlocked(udev->default_sx + 1)) {
- /* the caller is not properly locked */
- DPRINTF(-1, "not locked\n");
- return (USB_ERR_NOT_LOCKED);
+ /* automatic locking */
+ if (sx_xlocked(udev->default_sx + 1)) {
+ do_unlock = 0;
+ } else {
+ do_unlock = 1;
+ sx_xlock(udev->default_sx + 1);
}
+
/* detach all interface drivers */
usb2_detach_device(udev, USB_IFACE_INDEX_ANY, 1);
@@ -529,13 +533,13 @@
* the current config number and index.
*/
err = usb2_req_set_config(udev, &Giant, USB_UNCONFIG_NO);
- return (err);
+ goto done;
}
/* get the full config descriptor */
err = usb2_req_get_config_desc_full(udev,
&Giant, &cdp, M_USB, index);
if (err) {
- goto error;
+ goto done;
}
/* set the new config descriptor */
@@ -606,7 +610,7 @@
if (power > max_power) {
DPRINTF(-1, "power exceeded %d > %d\n", power, max_power);
err = USB_ERR_NO_POWER;
- goto error;
+ goto done;
}
/* Only update "self_powered" in USB Host Mode */
if (udev->flags.usb2_mode == USB_MODE_HOST) {
@@ -619,21 +623,25 @@
/* Set the actual configuration value. */
err = usb2_req_set_config(udev, &Giant, cdp->bConfigurationValue);
if (err) {
- goto error;
+ goto done;
}
/* Allocate and fill interface data. */
nifc = cdp->bNumInterface;
while (nifc--) {
err = usb2_fill_iface_data(udev, nifc, 0);
if (err) {
- goto error;
+ goto done;
}
}
- return (0);
-error:
+done:
DPRINTF(0, "error=%s\n", usb2_errstr(err));
- usb2_free_iface_data(udev);
+ if (err) {
+ usb2_free_iface_data(udev);
+ }
+ if (do_unlock) {
+ sx_unlock(udev->default_sx + 1);
+ }
return (err);
}
@@ -655,12 +663,14 @@
{
struct usb2_interface *iface = usb2_get_iface(udev, iface_index);
usb2_error_t err;
+ uint8_t do_unlock;
- if (!sx_xlocked(udev->default_sx + 1)) {
- /* the caller is not properly locked */
- DPRINTF(-1, "not locked\n");
- err = USB_ERR_NOT_LOCKED;
- goto done;
+ /* automatic locking */
+ if (sx_xlocked(udev->default_sx + 1)) {
+ do_unlock = 0;
+ } else {
+ do_unlock = 1;
+ sx_xlock(udev->default_sx + 1);
}
if (iface == NULL) {
err = USB_ERR_INVAL;
@@ -677,6 +687,9 @@
iface->idesc->bAlternateSetting);
done:
+ if (do_unlock) {
+ sx_unlock(udev->default_sx + 1);
+ }
return (err);
}
@@ -1041,16 +1054,23 @@
struct usb2_interface *iface;
uint8_t i;
uint8_t j;
+ uint8_t do_unlock;
if (udev == NULL) {
DPRINTF(0, "udev == NULL\n");
return (USB_ERR_INVAL);
}
- sx_assert(udev->default_sx + 1, SA_LOCKED);
+ /* automatic locking */
+ if (sx_xlocked(udev->default_sx + 1)) {
+ do_unlock = 0;
+ } else {
+ do_unlock = 1;
+ sx_xlock(udev->default_sx + 1);
+ }
if (udev->curr_config_index == USB_UNCONFIG_INDEX) {
/* do nothing - no configuration has been set */
- return (0);
+ goto done;
}
/* setup USB attach arguments */
@@ -1123,6 +1143,10 @@
DPRINTF(-1, "device delete child failed!\n");
}
}
+done:
+ if (do_unlock) {
+ sx_unlock(udev->default_sx + 1);
+ }
return (0);
}
==== //depot/projects/usb/src/sys/dev/usb2/core/usb2_hub.c#10 (text+ko) ====
@@ -227,10 +227,8 @@
if (child->driver_added_refcount != refcount) {
child->driver_added_refcount = refcount;
- sx_xlock(child->default_sx + 1);
err = usb2_probe_and_attach(child,
USB_IFACE_INDEX_ANY);
- sx_unlock(child->default_sx + 1);
if (err) {
goto done;
}
More information about the p4-projects
mailing list