Greg:

This patch changes the return codes used by hub_port_wait_reset(),
hub_port_reset(), and hub_port_debounce() in hub.c.  I couldn't stand the
{-1=error, 0=okay, 1=disconnect} scheme; the meanings seemed arbitrary and
I constantly forgot which number stood for what status.  The revised code
uses normal negative error codes, including -ENOTCONN to indicate device
disconnected, or 0 for success.

Please apply.

Alan Stern

P.S.: When hub_port_wait_reset() detects that the port isn't connected, it 
returns an indication that the device has gone away.  But when it detects 
a connection status change, it simply returns an error.  It seems to me 
that a connect change should be just as definitive as a not-connected 
status; either way it means the device was unplugged from the port.  If 
there was a connect change and something is connected now, then we should 
go back to the debounce step instead of continuing to try resetting the 
port.  Agreed?

P.P.S.: The hub_port_debounce() function doesn't behave as one would
expect from the comments at the top.  I trust no one will object if I
rewrite it to make the routine do what it's supposed to do?



# 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.2113  -> 1.2114 
#       drivers/usb/core/hub.c  1.157   -> 1.158  
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 04/05/25      [EMAIL PROTECTED]       1.2114
# Use normal return codes for several routines in hub.c
# --------------------------------------------
#
diff -Nru a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
--- a/drivers/usb/core/hub.c    Tue May 25 16:25:41 2004
+++ b/drivers/usb/core/hub.c    Tue May 25 16:25:41 2004
@@ -859,7 +859,6 @@
 #define HUB_LONG_RESET_TIME    200
 #define HUB_RESET_TIMEOUT      500
 
-/* return: -1 on error, 0 on success, 1 on disconnect.  */
 static int hub_port_wait_reset(struct usb_device *hdev, int port,
                                struct usb_device *udev, unsigned int delay)
 {
@@ -875,17 +874,16 @@
 
                /* read and decode port status */
                ret = hub_port_status(hdev, port, &portstatus, &portchange);
-               if (ret < 0) {
-                       return -1;
-               }
+               if (ret < 0)
+                       return ret;
 
                /* Device went away? */
                if (!(portstatus & USB_PORT_STAT_CONNECTION))
-                       return 1;
+                       return -ENOTCONN;
 
                /* bomb out completely if something weird happened */
                if ((portchange & USB_PORT_STAT_C_CONNECTION))
-                       return -1;
+                       return -EINVAL;
 
                /* if we`ve finished resetting, then break out of the loop */
                if (!(portstatus & USB_PORT_STAT_RESET) &&
@@ -908,10 +906,9 @@
                        port + 1, delay);
        }
 
-       return -1;
+       return -EBUSY;
 }
 
-/* return: -1 on error, 0 on success, 1 on disconnect.  */
 static int hub_port_reset(struct usb_device *hdev, int port,
                                struct usb_device *udev, unsigned int delay)
 {
@@ -924,7 +921,7 @@
 
                /* return on disconnect or reset */
                status = hub_port_wait_reset(hdev, port, udev, delay);
-               if (status != -1) {
+               if (status == -ENOTCONN || status == 0) {
                        clear_port_feature(hdev,
                                port + 1, USB_PORT_FEAT_C_RESET);
                        udev->state = status
@@ -943,7 +940,7 @@
                "Cannot enable port %i.  Maybe the USB cable is bad?\n",
                port + 1);
 
-       return -1;
+       return status;
 }
 
 static int hub_port_disable(struct usb_device *hdev, int port)
@@ -976,7 +973,6 @@
 #define HUB_DEBOUNCE_STEP       25
 #define HUB_DEBOUNCE_STABLE      4
 
-/* return: -1 on error, 0 on success, 1 on disconnect.  */
 static int hub_port_debounce(struct usb_device *hdev, int port)
 {
        int ret;
@@ -991,7 +987,7 @@
 
                ret = hub_port_status(hdev, port, &portstatus, &portchange);
                if (ret < 0)
-                       return -1;
+                       return ret;
 
                if ((portstatus & USB_PORT_STAT_CONNECTION) == connection) {
                        if (connection) {
@@ -1012,7 +1008,7 @@
                "debounce: port %d: delay %dms stable %d status 0x%x\n",
                port + 1, delay_time, stable_count, portstatus);
 
-       return ((portstatus&USB_PORT_STAT_CONNECTION)) ? 0 : 1;
+       return (portstatus & USB_PORT_STAT_CONNECTION) ? 0 : -ENOTCONN;
 }
 
 static int hub_set_address(struct usb_device *udev)
@@ -1045,7 +1041,7 @@
 {
        static DECLARE_MUTEX(usb_address0_sem);
 
-       int                     i, j, retval = -ENODEV;
+       int                     i, j, retval;
        unsigned                delay = HUB_SHORT_RESET_TIME;
        enum usb_device_speed   oldspeed = udev->speed;
 
@@ -1063,15 +1059,12 @@
        down(&usb_address0_sem);
 
        /* Reset the device; full speed may morph to high speed */
-       switch (hub_port_reset(hdev, port, udev, delay)) {
-       case 0:                 /* success, speed is known */
-               break;
-       case 1:                 /* disconnect, give to companion */
-               retval = -EBUSY;
-               /* FALL THROUGH */
-       default:                /* error */
+       retval = hub_port_reset(hdev, port, udev, delay);
+       if (retval < 0)         /* error or disconnect */
                goto fail;
-       }
+                               /* success, speed is known */
+       retval = -ENODEV;
+
        if (oldspeed != USB_SPEED_UNKNOWN && oldspeed != udev->speed) {
                dev_dbg(&udev->dev, "device reset changed speed!\n");
                goto fail;
@@ -1329,7 +1322,7 @@
                /* reset, set address, get descriptor, add to hub's children */
                down (&udev->serialize);
                status = hub_port_init(hdev, udev, port);
-               if (status == -EBUSY)
+               if (status == -ENOTCONN)
                        break;
                if (status < 0)
                        continue;



-------------------------------------------------------
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

Reply via email to