Bugfixes: - consistent cleanup, and consistent return of -Ewhatever/0; - a usb_put_dev() gets rid of the extra refcount; this one's in bugzilla at osdl.
Diagnostics: - new diagnostic for when there's a choice of configurations; - merges some diagnostics, for slight rodata reduction.
Please merge.
- Dave
--- 1.132/drivers/usb/core/usb.c Thu Jul 31 09:54:48 2003
+++ edited/drivers/usb/core/usb.c Tue Aug 5 16:09:10 2003
@@ -1056,7 +1056,7 @@
#define SET_ADDRESS_RETRYS 2
int usb_new_device(struct usb_device *dev, struct device *parent)
{
- int err = 0;
+ int err = -EINVAL;
int i;
int j;
@@ -1098,7 +1098,7 @@
i = 8;
break;
default:
- return -EINVAL;
+ goto fail;
}
dev->epmaxpacketin [0] = i;
dev->epmaxpacketout[0] = i;
@@ -1112,12 +1112,10 @@
wait_ms(200);
}
if (err < 0) {
- dev_err(&dev->dev, "USB device not accepting new address=%d
(error=%d)\n",
+ dev_err(&dev->dev,
+ "device not accepting address %d, error %d\n",
dev->devnum, err);
- dev->state = USB_STATE_DEFAULT;
- clear_bit(dev->devnum, dev->bus->devmap.devicemap);
- dev->devnum = -1;
- return 1;
+ goto fail;
}
wait_ms(10); /* Let the SET_ADDRESS settle */
@@ -1130,13 +1128,8 @@
}
if (err < 8) {
- if (err < 0)
- dev_err(&dev->dev, "USB device not responding, giving up
(error=%d)\n", err);
- else
- dev_err(&dev->dev, "USB device descriptor short read (expected
%i, got %i)\n", 8, err);
- clear_bit(dev->devnum, dev->bus->devmap.devicemap);
- dev->devnum = -1;
- return 1;
+ dev_err(&dev->dev, "device descriptor read/8, error %d\n", err);
+ goto fail;
}
if (dev->speed == USB_SPEED_FULL) {
dev->epmaxpacketin [0] = dev->descriptor.bMaxPacketSize0;
@@ -1147,34 +1140,29 @@
err = usb_get_device_descriptor(dev);
if (err < (signed)sizeof(dev->descriptor)) {
- if (err < 0)
- dev_err(&dev->dev, "unable to get device descriptor
(error=%d)\n", err);
- else
- dev_err(&dev->dev, "USB device descriptor short read (expected
%Zi, got %i)\n",
- sizeof(dev->descriptor), err);
-
- clear_bit(dev->devnum, dev->bus->devmap.devicemap);
- dev->devnum = -1;
- return 1;
+ dev_err(&dev->dev, "device descriptor read/all, error %d\n", err);
+ goto fail;
}
err = usb_get_configuration(dev);
if (err < 0) {
dev_err(&dev->dev, "unable to get device %d configuration
(error=%d)\n",
dev->devnum, err);
- clear_bit(dev->devnum, dev->bus->devmap.devicemap);
- dev->devnum = -1;
- return 1;
+ goto fail;
}
- /* we set the default configuration here */
+ /* choose and set the configuration here */
+ if (dev->descriptor.bNumConfigurations != 1) {
+ dev_info(&dev->dev,
+ "configuration #%d chosen from %d choices\n",
+ dev->config[0].desc.bConfigurationValue,
+ dev->descriptor.bNumConfigurations);
+ }
err = usb_set_configuration(dev, dev->config[0].desc.bConfigurationValue);
if (err) {
dev_err(&dev->dev, "failed to set device %d default configuration
(error=%d)\n",
dev->devnum, err);
- clear_bit(dev->devnum, dev->bus->devmap.devicemap);
- dev->devnum = -1;
- return 1;
+ goto fail;
}
/* USB device state == configured ... tell the world! */
@@ -1191,7 +1179,7 @@
/* put into sysfs, with device and config specific files */
err = device_add (&dev->dev);
if (err)
- return err;
+ goto fail;
usb_create_driverfs_dev_files (dev);
/* Register all of the interfaces for this device with the driver core.
@@ -1231,6 +1219,12 @@
usbfs_add_device(dev);
return 0;
+fail:
+ dev->state = USB_STATE_DEFAULT;
+ clear_bit(dev->devnum, dev->bus->devmap.devicemap);
+ dev->devnum = -1;
+ usb_put_dev(dev);
+ return err;
}
/**
