Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

USB: avoid error messages when a device is disconnected

This patch (as1673) reduces the amount of log spew from the hub driver
by removing a bunch of error messages in the case where the device in
question is already known to have been disconnected. Since the
disconnect event itself appears in the log, there's no need for other
error messages.

Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Tested-by: Jenya Y <jy.gerstmaier@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Alan Stern and committed by
Greg Kroah-Hartman
e9e88fb7 b1337975

+37 -30
+1 -1
drivers/usb/core/generic.c
··· 169 169 c = usb_choose_configuration(udev); 170 170 if (c >= 0) { 171 171 err = usb_set_configuration(udev, c); 172 - if (err) { 172 + if (err && err != -ENODEV) { 173 173 dev_err(&udev->dev, "can't set config #%d, error %d\n", 174 174 c, err); 175 175 /* This need not be fatal. The user can try to
+36 -29
drivers/usb/core/hub.c
··· 555 555 mutex_lock(&hub->status_mutex); 556 556 ret = get_port_status(hub->hdev, port1, &hub->status->port); 557 557 if (ret < 4) { 558 - dev_err(hub->intfdev, 559 - "%s failed (err = %d)\n", __func__, ret); 558 + if (ret != -ENODEV) 559 + dev_err(hub->intfdev, 560 + "%s failed (err = %d)\n", __func__, ret); 560 561 if (ret >= 0) 561 562 ret = -EIO; 562 563 } else { ··· 700 699 /* drop lock so HCD can concurrently report other TT errors */ 701 700 spin_unlock_irqrestore (&hub->tt.lock, flags); 702 701 status = hub_clear_tt_buffer (hdev, clear->devinfo, clear->tt); 703 - if (status) 702 + if (status && status != -ENODEV) 704 703 dev_err (&hdev->dev, 705 704 "clear tt %d (%04x) error %d\n", 706 705 clear->tt, clear->devinfo, status); ··· 838 837 839 838 mutex_lock(&hub->status_mutex); 840 839 ret = get_hub_status(hub->hdev, &hub->status->hub); 841 - if (ret < 0) 842 - dev_err (hub->intfdev, 843 - "%s failed (err = %d)\n", __func__, ret); 844 - else { 840 + if (ret < 0) { 841 + if (ret != -ENODEV) 842 + dev_err(hub->intfdev, 843 + "%s failed (err = %d)\n", __func__, ret); 844 + } else { 845 845 *status = le16_to_cpu(hub->status->hub.wHubStatus); 846 846 *change = le16_to_cpu(hub->status->hub.wHubChange); 847 847 ret = 0; ··· 879 877 return -EINVAL; 880 878 881 879 ret = hub_set_port_link_state(hub, port1, USB_SS_PORT_LS_SS_DISABLED); 882 - if (ret) { 883 - dev_err(hub->intfdev, "cannot disable port %d (err = %d)\n", 884 - port1, ret); 880 + if (ret) 885 881 return ret; 886 - } 887 882 888 883 /* Wait for the link to enter the disabled state. */ 889 884 for (total_time = 0; ; total_time += HUB_DEBOUNCE_STEP) { ··· 917 918 ret = usb_clear_port_feature(hdev, port1, 918 919 USB_PORT_FEAT_ENABLE); 919 920 } 920 - if (ret) 921 + if (ret && ret != -ENODEV) 921 922 dev_err(hub->intfdev, "cannot disable port %d (err = %d)\n", 922 923 port1, ret); 923 924 return ret; ··· 2195 2196 if (udev->config == NULL) { 2196 2197 err = usb_get_configuration(udev); 2197 2198 if (err < 0) { 2198 - dev_err(&udev->dev, "can't read configurations, error %d\n", 2199 - err); 2199 + if (err != -ENODEV) 2200 + dev_err(&udev->dev, "can't read configurations, error %d\n", 2201 + err); 2200 2202 return err; 2201 2203 } 2202 2204 } ··· 2644 2644 status = set_port_feature(hub->hdev, port1, (warm ? 2645 2645 USB_PORT_FEAT_BH_PORT_RESET : 2646 2646 USB_PORT_FEAT_RESET)); 2647 - if (status) { 2647 + if (status == -ENODEV) { 2648 + ; /* The hub is gone */ 2649 + } else if (status) { 2648 2650 dev_err(hub->intfdev, 2649 2651 "cannot %sreset port %d (err = %d)\n", 2650 2652 warm ? "warm " : "", port1, status); 2651 2653 } else { 2652 2654 status = hub_port_wait_reset(hub, port1, udev, delay, 2653 2655 warm); 2654 - if (status && status != -ENOTCONN) 2656 + if (status && status != -ENOTCONN && status != -ENODEV) 2655 2657 dev_dbg(hub->intfdev, 2656 2658 "port_wait_reset: err = %d\n", 2657 2659 status); ··· 4096 4094 goto fail; 4097 4095 } 4098 4096 if (r) { 4099 - dev_err(&udev->dev, 4100 - "device descriptor read/64, error %d\n", 4101 - r); 4097 + if (r != -ENODEV) 4098 + dev_err(&udev->dev, "device descriptor read/64, error %d\n", 4099 + r); 4102 4100 retval = -EMSGSIZE; 4103 4101 continue; 4104 4102 } ··· 4118 4116 msleep(200); 4119 4117 } 4120 4118 if (retval < 0) { 4121 - dev_err(&udev->dev, 4122 - "device not accepting address %d, error %d\n", 4123 - devnum, retval); 4119 + if (retval != -ENODEV) 4120 + dev_err(&udev->dev, "device not accepting address %d, error %d\n", 4121 + devnum, retval); 4124 4122 goto fail; 4125 4123 } 4126 4124 if (udev->speed == USB_SPEED_SUPER) { ··· 4142 4140 4143 4141 retval = usb_get_device_descriptor(udev, 8); 4144 4142 if (retval < 8) { 4145 - dev_err(&udev->dev, 4143 + if (retval != -ENODEV) 4144 + dev_err(&udev->dev, 4146 4145 "device descriptor read/8, error %d\n", 4147 4146 retval); 4148 4147 if (retval >= 0) ··· 4197 4194 4198 4195 retval = usb_get_device_descriptor(udev, USB_DT_DEVICE_SIZE); 4199 4196 if (retval < (signed)sizeof(udev->descriptor)) { 4200 - dev_err(&udev->dev, "device descriptor read/all, error %d\n", 4201 - retval); 4197 + if (retval != -ENODEV) 4198 + dev_err(&udev->dev, "device descriptor read/all, error %d\n", 4199 + retval); 4202 4200 if (retval >= 0) 4203 4201 retval = -ENOMSG; 4204 4202 goto fail; ··· 4381 4377 USB_PORT_STAT_C_ENABLE)) { 4382 4378 status = hub_port_debounce_be_stable(hub, port1); 4383 4379 if (status < 0) { 4384 - if (printk_ratelimit()) 4380 + if (status != -ENODEV && printk_ratelimit()) 4385 4381 dev_err(hub_dev, "connect-debounce failed, " 4386 4382 "port %d disabled\n", port1); 4387 4383 portstatus &= ~USB_PORT_STAT_CONNECTION; ··· 4410 4406 else 4411 4407 unit_load = 100; 4412 4408 4409 + status = 0; 4413 4410 for (i = 0; i < SET_CONFIG_TRIES; i++) { 4414 4411 4415 4412 /* reallocate for each attempt, since references ··· 4535 4530 } 4536 4531 if (hub->hdev->parent || 4537 4532 !hcd->driver->port_handed_over || 4538 - !(hcd->driver->port_handed_over)(hcd, port1)) 4539 - dev_err(hub_dev, "unable to enumerate USB device on port %d\n", 4540 - port1); 4533 + !(hcd->driver->port_handed_over)(hcd, port1)) { 4534 + if (status != -ENOTCONN && status != -ENODEV) 4535 + dev_err(hub_dev, "unable to enumerate USB device on port %d\n", 4536 + port1); 4537 + } 4541 4538 4542 4539 done: 4543 4540 hub_port_disable(hub, port1, 1);