Greg:
This patch adds usb_release_address() as a complement to
usb_choose_address(), to centralize the work required when freeing an
allocated device address. It also moves the usb_set_address() routine
from usb.c to hub.c -- which is the only place it is ever used -- and
renames it to hub_set_address().
Please apply.
Alan Stern
# This is a BitKeeper generated patch for the following project:
# Project Name: greg k-h's linux 2.5 USB kernel tree
# This patch format is intended for GNU patch command version 2.5 or higher.
# This patch includes the following deltas:
# ChangeSet 1.2110 -> 1.2111
# drivers/usb/core/usb.c 1.271 -> 1.272
# drivers/usb/core/hub.c 1.155 -> 1.156
# drivers/usb/core/hcd.h 1.72 -> 1.73
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 04/05/24 [EMAIL PROTECTED] 1.2111
# Add usb_release_address(), and move usb_set_address() into hub.c.
# --------------------------------------------
#
diff -Nru a/drivers/usb/core/hcd.h b/drivers/usb/core/hcd.h
--- a/drivers/usb/core/hcd.h Mon May 24 10:29:23 2004
+++ b/drivers/usb/core/hcd.h Mon May 24 10:29:23 2004
@@ -243,13 +243,13 @@
extern struct usb_device *usb_alloc_dev(struct usb_device *parent,
struct usb_bus *, unsigned port);
extern int usb_new_device(struct usb_device *dev);
-extern void usb_choose_address(struct usb_device *dev);
extern void usb_disconnect(struct usb_device **);
+extern void usb_choose_address(struct usb_device *dev);
+extern void usb_release_address(struct usb_device *dev);
/* exported to hub driver ONLY to support usb_reset_device () */
extern int usb_get_configuration(struct usb_device *dev);
extern void usb_destroy_configuration(struct usb_device *dev);
-extern int usb_set_address(struct usb_device *dev);
/* use these only before the device's address has been set */
#define usb_snddefctrl(dev) ((PIPE_CONTROL << 30))
diff -Nru a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
--- a/drivers/usb/core/hub.c Mon May 24 10:29:23 2004
+++ b/drivers/usb/core/hub.c Mon May 24 10:29:23 2004
@@ -1013,6 +1013,21 @@
return ((portstatus&USB_PORT_STAT_CONNECTION)) ? 0 : 1;
}
+static int hub_set_address(struct usb_device *dev)
+{
+ int retval;
+
+ if (dev->devnum == 0)
+ return -EINVAL;
+ if (dev->state != USB_STATE_DEFAULT && dev->state != USB_STATE_ADDRESS)
+ return -EINVAL;
+ retval = usb_control_msg(dev, usb_snddefctrl(dev), USB_REQ_SET_ADDRESS,
+ 0, dev->devnum, 0, NULL, 0, HZ * USB_CTRL_SET_TIMEOUT);
+ if (retval == 0)
+ dev->state = USB_STATE_ADDRESS;
+ return retval;
+}
+
/* reset device, (re)assign address, get device descriptor.
* device connection is stable, no more debouncing needed.
* returns device in USB_STATE_ADDRESS, except on error.
@@ -1126,7 +1141,7 @@
*/
for (i = 0; i < GET_DESCRIPTOR_TRIES; ++i) {
for (j = 0; j < SET_ADDRESS_TRIES; ++j) {
- retval = usb_set_address(dev);
+ retval = hub_set_address(dev);
if (retval >= 0)
break;
msleep(200);
@@ -1137,8 +1152,7 @@
dev->devnum, retval);
fail:
hub_port_disable(hub, port);
- clear_bit(dev->devnum, dev->bus->devmap.devicemap);
- dev->devnum = -1;
+ usb_release_address(dev);
usb_put_dev(dev);
up(&usb_address0_sem);
return retval;
diff -Nru a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
--- a/drivers/usb/core/usb.c Mon May 24 10:29:23 2004
+++ b/drivers/usb/core/usb.c Mon May 24 10:29:23 2004
@@ -998,12 +998,10 @@
*/
usb_disable_device(dev, 0);
- dev_dbg (&dev->dev, "unregistering device\n");
/* Free the device number and remove the /proc/bus/usb entry */
- if (dev->devnum > 0) {
- clear_bit(dev->devnum, dev->bus->devmap.devicemap);
- usbfs_remove_device(dev);
- }
+ dev_dbg (&dev->dev, "unregistering device\n");
+ usb_release_address(dev);
+ usbfs_remove_device(dev);
up(&dev->serialize);
device_unregister(&dev->dev);
}
@@ -1038,24 +1036,23 @@
}
}
-
-// hub-only!! ... and only exported for reset/reinit path.
-// otherwise used internally, for usb_new_device()
-int usb_set_address(struct usb_device *dev)
+/**
+ * usb_release_address - deallocate device address (usbcore-internal)
+ * @dev: newly removed device
+ *
+ * Removes and deallocates the address assigned to a device.
+ * Only hub drivers (but not virtual root hub drivers for host
+ * controllers) should ever call this.
+ */
+void usb_release_address(struct usb_device *dev)
{
- int retval;
-
- if (dev->devnum == 0)
- return -EINVAL;
- if (dev->state != USB_STATE_DEFAULT && dev->state != USB_STATE_ADDRESS)
- return -EINVAL;
- retval = usb_control_msg(dev, usb_snddefctrl(dev), USB_REQ_SET_ADDRESS,
- 0, dev->devnum, 0, NULL, 0, HZ * USB_CTRL_SET_TIMEOUT);
- if (retval == 0)
- dev->state = USB_STATE_ADDRESS;
- return retval;
+ if (dev->devnum > 0) {
+ clear_bit(dev->devnum, dev->bus->devmap.devicemap);
+ dev->devnum = -1;
+ }
}
+
static inline void usb_show_string(struct usb_device *dev, char *id, int index)
{
char *buf;
@@ -1166,8 +1163,7 @@
return 0;
fail:
dev->state = USB_STATE_NOTATTACHED;
- clear_bit(dev->devnum, dev->bus->devmap.devicemap);
- dev->devnum = -1;
+ usb_release_address(dev);
usb_put_dev(dev);
return err;
}
-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g.
Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click
_______________________________________________
[EMAIL PROTECTED]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel