1: Remove unnecessary spaces after dev_dbg/err/info functions
2: Expand compressed switches, one of which had unreachable code
3: Create and use check_port_status_changes, removes an indent level

signed-off-by: Joe Perches <[EMAIL PROTECTED]>

diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 875596e..3827106 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -151,18 +151,29 @@ static void set_port_led(
 {
        int status = set_port_feature(hub->hdev, (selector << 8) | port1,
                        USB_PORT_FEAT_INDICATOR);
-       if (status < 0)
-               dev_dbg (hub->intfdev,
+       if (status < 0) {
+               char *s;
+               switch (selector) {
+               case HUB_LED_AMBER:
+                       s = "amber";
+                       break;
+               case HUB_LED_GREEN:
+                       s = "green";
+                       break;
+               case HUB_LED_OFF:
+                       s = "off";
+                       break;
+               case HUB_LED_AUTO:
+                       s = "auto";
+                       break;
+               default:
+                       s = "??";
+                       break;
+               }
+               dev_dbg(hub->intfdev,
                        "port %d indicator %s status %d\n",
-                       port1,
-                       ({ char *s; switch (selector) {
-                       case HUB_LED_AMBER: s = "amber"; break;
-                       case HUB_LED_GREEN: s = "green"; break;
-                       case HUB_LED_OFF: s = "off"; break;
-                       case HUB_LED_AUTO: s = "auto"; break;
-                       default: s = "??"; break;
-                       }; s; }),
-                       status);
+                       port1, s, status);
+       }
 }
 
 #define        LED_CYCLE_PERIOD        ((2*HZ)/3)
@@ -373,7 +384,7 @@ static void hub_tt_kevent (void *arg)
                spin_lock_irqsave (&hub->tt.lock, flags);
 
                if (status)
-                       dev_err (&hdev->dev,
+                       dev_err(&hdev->dev,
                                "clear tt %d (%04x) error %d\n",
                                clear->tt, clear->devinfo, status);
                kfree(clear);
@@ -405,7 +416,7 @@ void usb_hub_tt_clear_buffer (struct usb
         * there can be many TTs per hub).  even if they're uncommon.
         */
        if ((clear = kmalloc (sizeof *clear, SLAB_ATOMIC)) == NULL) {
-               dev_err (&udev->dev, "can't save CLEAR_TT_BUFFER state\n");
+               dev_err(&udev->dev, "can't save CLEAR_TT_BUFFER state\n");
                /* FIXME recover somehow ... RESET_TT? */
                return;
        }
@@ -495,7 +506,7 @@ static int hub_hub_status(struct usb_hub
 
        ret = get_hub_status(hub->hdev, &hub->status->hub);
        if (ret < 0)
-               dev_err (hub->intfdev,
+               dev_err(hub->intfdev,
                        "%s failed (err = %d)\n", __FUNCTION__, ret);
        else {
                *status = le16_to_cpu(hub->status->hub.wHubStatus);
@@ -599,8 +610,8 @@ static int hub_configure(struct usb_hub 
        }
 
        hdev->maxchild = hub->descriptor->bNbrPorts;
-       dev_info (hub_dev, "%d port%s detected\n", hdev->maxchild,
-               (hdev->maxchild == 1) ? "" : "s");
+       dev_info(hub_dev, "%d port%s detected\n", hdev->maxchild,
+                (hdev->maxchild == 1) ? "" : "s");
 
        wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics);
 
@@ -791,8 +802,8 @@ static int hub_configure(struct usb_hub 
        return 0;
 
 fail:
-       dev_err (hub_dev, "config failed, %s (err %d)\n",
-                       message, ret);
+       dev_err(hub_dev, "config failed, %s (err %d)\n",
+               message, ret);
        /* hub_disconnect() frees urb and descriptor */
        return ret;
 }
@@ -858,7 +869,7 @@ static int hub_probe(struct usb_interfac
        if ((desc->desc.bInterfaceSubClass != 0) &&
            (desc->desc.bInterfaceSubClass != 1)) {
 descriptor_error:
-               dev_err (&intf->dev, "bad descriptor, ignoring hub\n");
+               dev_err(&intf->dev, "bad descriptor, ignoring hub\n");
                return -EIO;
        }
 
@@ -878,11 +889,11 @@ descriptor_error:
                goto descriptor_error;
 
        /* We found a hub */
-       dev_info (&intf->dev, "USB hub found\n");
+       dev_info(&intf->dev, "USB hub found\n");
 
        hub = kzalloc(sizeof(*hub), GFP_KERNEL);
        if (!hub) {
-               dev_dbg (&intf->dev, "couldn't kmalloc hub struct\n");
+               dev_dbg(&intf->dev, "couldn't kmalloc hub struct\n");
                return -ENOMEM;
        }
 
@@ -1134,7 +1145,7 @@ void usb_disconnect(struct usb_device **
         * this quiesces everyting except pending urbs.
         */
        usb_set_device_state(udev, USB_STATE_NOTATTACHED);
-       dev_info (&udev->dev, "USB disconnect, address %d\n", udev->devnum);
+       dev_info(&udev->dev, "USB disconnect, address %d\n", udev->devnum);
 
        usb_lock_device(udev);
 
@@ -1156,7 +1167,7 @@ void usb_disconnect(struct usb_device **
         * the sysfs attributes, and delete the parent's children[]
         * (or root_hub) pointer.
         */
-       dev_dbg (&udev->dev, "unregistering device\n");
+       dev_dbg(&udev->dev, "unregistering device\n");
        release_address(udev);
        usb_remove_sysfs_dev_files(udev);
 
@@ -1293,7 +1304,7 @@ static void show_string(struct usb_devic
 {
        if (!string)
                return;
-       dev_printk(KERN_INFO, &udev->dev, "%s: %s\n", id, string);
+       dev_info(&udev->dev, "%s: %s\n", id, string);
 }
 
 #else
@@ -1424,7 +1435,7 @@ int usb_new_device(struct usb_device *ud
                dev_err(&udev->dev, "can't device_add, error %d\n", err);
                goto fail;
        }
-       usb_create_sysfs_dev_files (udev);
+       usb_create_sysfs_dev_files(udev);
 
        usb_lock_device(udev);
 
@@ -1462,7 +1473,7 @@ static int hub_port_status(struct usb_hu
 
        ret = get_port_status(hub->hdev, port1, &hub->status->port);
        if (ret < 0)
-               dev_err (hub->intfdev,
+               dev_err(hub->intfdev,
                        "%s failed (err = %d)\n", __FUNCTION__, ret);
        else {
                *status = le16_to_cpu(hub->status->port.wPortStatus);
@@ -1525,7 +1536,7 @@ static int hub_port_wait_reset(struct us
                if (delay_time >= 2 * HUB_SHORT_RESET_TIME)
                        delay = HUB_LONG_RESET_TIME;
 
-               dev_dbg (hub->intfdev,
+               dev_dbg(hub->intfdev,
                        "port %d not reset yet, waiting %dms\n",
                        port1, delay);
        }
@@ -1571,13 +1582,13 @@ static int hub_port_reset(struct usb_hub
                        return status;
                }
 
-               dev_dbg (hub->intfdev,
+               dev_dbg(hub->intfdev,
                        "port %d not enabled, trying reset again...\n",
                        port1);
                delay = HUB_LONG_RESET_TIME;
        }
 
-       dev_err (hub->intfdev,
+       dev_err(hub->intfdev,
                "Cannot enable port %i.  Maybe the USB cable is bad?\n",
                port1);
 
@@ -2148,7 +2159,7 @@ static int hub_port_debounce(struct usb_
                msleep(HUB_DEBOUNCE_STEP);
        }
 
-       dev_dbg (hub->intfdev,
+       dev_dbg(hub->intfdev,
                "debounce: port %d: total %dms stable %dms status 0x%x\n",
                port1, total_time, stable_time, portstatus);
 
@@ -2206,6 +2217,7 @@ hub_port_init (struct usb_hub *hub, stru
        int                     i, j, retval;
        unsigned                delay = HUB_SHORT_RESET_TIME;
        enum usb_device_speed   oldspeed = udev->speed;
+       char                    *speed;
 
        /* root hub ports have a slightly longer reset period
         * (from USB 2.0 spec, section 7.1.7.5)
@@ -2242,6 +2254,7 @@ hub_port_init (struct usb_hub *hub, stru
        switch (udev->speed) {
        case USB_SPEED_HIGH:            /* fixed at 64 */
                udev->ep0.desc.wMaxPacketSize = __constant_cpu_to_le16(64);
+               speed = "high";
                break;
        case USB_SPEED_FULL:            /* 8, 16, 32, or 64 */
                /* to determine the ep0 maxpacket size, try to read
@@ -2249,25 +2262,22 @@ hub_port_init (struct usb_hub *hub, stru
                 * then correct our initial guess.
                 */
                udev->ep0.desc.wMaxPacketSize = __constant_cpu_to_le16(64);
+               speed = "full";
                break;
        case USB_SPEED_LOW:             /* fixed at 8 */
                udev->ep0.desc.wMaxPacketSize = __constant_cpu_to_le16(8);
+               speed = "low";
                break;
        default:
                goto fail;
        }
  
-       dev_info (&udev->dev,
-                       "%s %s speed USB device using %s and address %d\n",
-                       (udev->config) ? "reset" : "new",
-                       ({ char *speed; switch (udev->speed) {
-                       case USB_SPEED_LOW:     speed = "low";  break;
-                       case USB_SPEED_FULL:    speed = "full"; break;
-                       case USB_SPEED_HIGH:    speed = "high"; break;
-                       default:                speed = "?";    break;
-                       }; speed;}),
-                       udev->bus->controller->driver->name,
-                       udev->devnum);
+       dev_info(&udev->dev,
+                "%s %s speed USB device using %s and address %d\n",
+                (udev->config) ? "reset" : "new",
+                speed,
+                udev->bus->controller->driver->name,
+                udev->devnum);
 
        /* Set up TT records, if needed  */
        if (hdev->tt) {
@@ -2503,7 +2513,7 @@ static void hub_port_connect_change(stru
        u16 wHubCharacteristics = 
le16_to_cpu(hub->descriptor->wHubCharacteristics);
        int status, i;
  
-       dev_dbg (hub_dev,
+       dev_dbg(hub_dev,
                "port %d, status %04x, change %04x, %s\n",
                port1, portstatus, portchange, portspeed (portstatus));
 
@@ -2526,7 +2536,7 @@ static void hub_port_connect_change(stru
        if (portchange & USB_PORT_STAT_C_CONNECTION) {
                status = hub_port_debounce(hub, port1);
                if (status < 0) {
-                       dev_err (hub_dev,
+                       dev_err(hub_dev,
                                "connect-debounce failed, port %d disabled\n",
                                port1);
                        goto done;
@@ -2568,7 +2578,7 @@ static void hub_port_connect_change(stru
                 */
                udev = usb_alloc_dev(hdev, hdev->bus, port1);
                if (!udev) {
-                       dev_err (hub_dev,
+                       dev_err(hub_dev,
                                "couldn't allocate port %d usb_device\n",
                                port1);
                        goto done;
@@ -2677,6 +2687,101 @@ done:
        hub_port_disable(hub, port1, 1);
 }
 
+static void check_port_status_changes(struct usb_hub *hub)
+{
+       u16 portstatus;
+       u16 portchange;
+       int i, ret;
+       int connect_change;
+       struct usb_device *hdev = hub->hdev;
+       struct usb_interface *intf = to_usb_interface(hub->intfdev);
+       struct device *hub_dev = &intf->dev;
+
+       /* deal with port status changes */
+       for (i = 1; i <= hub->descriptor->bNbrPorts; i++) {
+               if (test_bit(i, hub->busy_bits))
+                       continue;
+               connect_change = test_bit(i, hub->change_bits);
+               if (!test_and_clear_bit(i, hub->event_bits) &&
+                   !connect_change && !hub->activating)
+                       continue;
+
+               ret = hub_port_status(hub, i, &portstatus, &portchange);
+               if (ret < 0)
+                       continue;
+
+               if (hub->activating && !hdev->children[i-1] &&
+                   (portstatus & USB_PORT_STAT_CONNECTION))
+                       connect_change = 1;
+
+               if (portchange & USB_PORT_STAT_C_CONNECTION) {
+                       clear_port_feature(hdev, i,
+                                          USB_PORT_FEAT_C_CONNECTION);
+                       connect_change = 1;
+               }
+
+               if (portchange & USB_PORT_STAT_C_ENABLE) {
+                       if (!connect_change)
+                               dev_dbg(hub_dev,
+                                       "port %d enable change, status %08x\n",
+                                       i, portstatus);
+                       clear_port_feature(hdev, i, USB_PORT_FEAT_C_ENABLE);
+
+                       /*
+                        * EM interference sometimes causes badly
+                        * shielded USB devices to be shutdown by
+                        * the hub, this hack enables them again.
+                        * Works at least with mouse driver. 
+                        */
+                       if (!(portstatus & USB_PORT_STAT_ENABLE) &&
+                           !connect_change && hdev->children[i-1]) {
+                               dev_err(hub_dev,
+                                       "port %i disabled by hub (EMI?), "
+                                       "re-enabling...\n",
+                                       i);
+                               connect_change = 1;
+                       }
+               }
+
+               if (portchange & USB_PORT_STAT_C_SUSPEND) {
+                       clear_port_feature(hdev, i, USB_PORT_FEAT_C_SUSPEND);
+                       if (hdev->children[i-1]) {
+                               ret = remote_wakeup(hdev->children[i-1]);
+                               if (ret < 0)
+                                       connect_change = 1;
+                       } else {
+                               ret = -ENODEV;
+                               hub_port_disable(hub, i, 1);
+                       }
+                       dev_dbg(hub_dev,
+                               "resume on port %d, status %d\n",
+                               i, ret);
+               }
+
+               if (portchange & USB_PORT_STAT_C_OVERCURRENT) {
+                       dev_err(hub_dev,
+                               "over-current change on port %d\n",
+                               i);
+                       clear_port_feature(hdev, i,
+                                          USB_PORT_FEAT_C_OVER_CURRENT);
+                       hub_power_on(hub);
+               }
+
+               if (portchange & USB_PORT_STAT_C_RESET) {
+                       dev_dbg(hub_dev,
+                               "reset change on port %d\n",
+                               i);
+                       clear_port_feature(hdev, i,
+                                          USB_PORT_FEAT_C_RESET);
+               }
+ 
+               if (connect_change)
+                       hub_port_connect_change(hub, i,
+                                               portstatus, portchange);
+       } /* end for i */
+}
+
+
 static void hub_events(void)
 {
        struct list_head *tmp;
@@ -2686,10 +2791,7 @@ static void hub_events(void)
        struct device *hub_dev;
        u16 hubstatus;
        u16 hubchange;
-       u16 portstatus;
-       u16 portchange;
        int i, ret;
-       int connect_change;
 
        /*
         *  We restart the list every time to avoid a deadlock with
@@ -2717,13 +2819,12 @@ static void hub_events(void)
                i = hub->resume_root_hub;
 
                dev_dbg(hub_dev, "state %d ports %d chg %04x evt %04x%s\n",
-                               hdev->state, hub->descriptor
-                                       ? hub->descriptor->bNbrPorts
-                                       : 0,
-                               /* NOTE: expects max 15 ports... */
-                               (u16) hub->change_bits[0],
-                               (u16) hub->event_bits[0],
-                               i ? ", resume root" : "");
+                       hdev->state,
+                       hub->descriptor ? hub->descriptor->bNbrPorts : 0,
+                       /* NOTE: expects max 15 ports... */
+                       (u16) hub->change_bits[0],
+                       (u16) hub->event_bits[0],
+                       i ? ", resume root" : "");
 
                usb_get_intf(intf);
                spin_unlock_irq(&hub_event_lock);
@@ -2760,12 +2861,12 @@ static void hub_events(void)
                        goto loop;
 
                if (hub->error) {
-                       dev_dbg (hub_dev, "resetting for error %d\n",
+                       dev_dbg(hub_dev, "resetting for error %d\n",
                                hub->error);
 
                        ret = usb_reset_composite_device(hdev, intf);
                        if (ret) {
-                               dev_dbg (hub_dev,
+                               dev_dbg(hub_dev,
                                        "error resetting hub: %d\n", ret);
                                goto loop;
                        }
@@ -2774,105 +2875,16 @@ static void hub_events(void)
                        hub->error = 0;
                }
 
-               /* deal with port status changes */
-               for (i = 1; i <= hub->descriptor->bNbrPorts; i++) {
-                       if (test_bit(i, hub->busy_bits))
-                               continue;
-                       connect_change = test_bit(i, hub->change_bits);
-                       if (!test_and_clear_bit(i, hub->event_bits) &&
-                                       !connect_change && !hub->activating)
-                               continue;
-
-                       ret = hub_port_status(hub, i,
-                                       &portstatus, &portchange);
-                       if (ret < 0)
-                               continue;
-
-                       if (hub->activating && !hdev->children[i-1] &&
-                                       (portstatus &
-                                               USB_PORT_STAT_CONNECTION))
-                               connect_change = 1;
-
-                       if (portchange & USB_PORT_STAT_C_CONNECTION) {
-                               clear_port_feature(hdev, i,
-                                       USB_PORT_FEAT_C_CONNECTION);
-                               connect_change = 1;
-                       }
-
-                       if (portchange & USB_PORT_STAT_C_ENABLE) {
-                               if (!connect_change)
-                                       dev_dbg (hub_dev,
-                                               "port %d enable change, "
-                                               "status %08x\n",
-                                               i, portstatus);
-                               clear_port_feature(hdev, i,
-                                       USB_PORT_FEAT_C_ENABLE);
-
-                               /*
-                                * EM interference sometimes causes badly
-                                * shielded USB devices to be shutdown by
-                                * the hub, this hack enables them again.
-                                * Works at least with mouse driver. 
-                                */
-                               if (!(portstatus & USB_PORT_STAT_ENABLE)
-                                   && !connect_change
-                                   && hdev->children[i-1]) {
-                                       dev_err (hub_dev,
-                                           "port %i "
-                                           "disabled by hub (EMI?), "
-                                           "re-enabling...\n",
-                                               i);
-                                       connect_change = 1;
-                               }
-                       }
-
-                       if (portchange & USB_PORT_STAT_C_SUSPEND) {
-                               clear_port_feature(hdev, i,
-                                       USB_PORT_FEAT_C_SUSPEND);
-                               if (hdev->children[i-1]) {
-                                       ret = remote_wakeup(hdev->
-                                                       children[i-1]);
-                                       if (ret < 0)
-                                               connect_change = 1;
-                               } else {
-                                       ret = -ENODEV;
-                                       hub_port_disable(hub, i, 1);
-                               }
-                               dev_dbg (hub_dev,
-                                       "resume on port %d, status %d\n",
-                                       i, ret);
-                       }
-                       
-                       if (portchange & USB_PORT_STAT_C_OVERCURRENT) {
-                               dev_err (hub_dev,
-                                       "over-current change on port %d\n",
-                                       i);
-                               clear_port_feature(hdev, i,
-                                       USB_PORT_FEAT_C_OVER_CURRENT);
-                               hub_power_on(hub);
-                       }
-
-                       if (portchange & USB_PORT_STAT_C_RESET) {
-                               dev_dbg (hub_dev,
-                                       "reset change on port %d\n",
-                                       i);
-                               clear_port_feature(hdev, i,
-                                       USB_PORT_FEAT_C_RESET);
-                       }
-
-                       if (connect_change)
-                               hub_port_connect_change(hub, i,
-                                               portstatus, portchange);
-               } /* end for i */
+               check_port_status_changes(hub);
 
                /* deal with hub status changes */
                if (test_and_clear_bit(0, hub->event_bits) == 0)
                        ;       /* do nothing */
                else if (hub_hub_status(hub, &hubstatus, &hubchange) < 0)
-                       dev_err (hub_dev, "get_hub_status failed\n");
+                       dev_err(hub_dev, "get_hub_status failed\n");
                else {
                        if (hubchange & HUB_CHANGE_LOCAL_POWER) {
-                               dev_dbg (hub_dev, "power change\n");
+                               dev_dbg(hub_dev, "power change\n");
                                clear_hub_feature(hdev, C_HUB_LOCAL_POWER);
                                if (hubstatus & HUB_STATUS_LOCAL_POWER)
                                        /* FIXME: Is this always true? */
@@ -2881,7 +2893,7 @@ static void hub_events(void)
                                        hub->limited_power = 1;
                        }
                        if (hubchange & HUB_CHANGE_OVERCURRENT) {
-                               dev_dbg (hub_dev, "overcurrent change\n");
+                               dev_dbg(hub_dev, "overcurrent change\n");
                                msleep(500);    /* Cool down */
                                clear_hub_feature(hdev, C_HUB_OVER_CURRENT);
                                hub_power_on(hub);




-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
linux-usb-devel@lists.sourceforge.net
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to