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

USB: Don't rebind before "complete" callback

This patch (as1130) fixes an incompatibility between the new PM
infrastructure and USB power management. We are not allowed to call
drivers' probe routines during a system sleep transition between the
"prepare" and "complete" callbacks, but that's exactly what we do when
a driver doesn't have full suspend/resume support. Such drivers are
unbound during the "suspend" call and reprobed during the "resume" call.

The patch causes the reprobe step to be skipped if the "complete"
callback hasn't been issued yet, i.e., if the interface's
dev.power.status field is not equal to DPM_ON. Thus during the
"resume" callback nothing bad will happen, and during the final
"complete" callback the reprobing will occur as desired.

This fixes the problem reported in Bugzilla #11263.

Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by

Alan Stern and committed by
Greg Kroah-Hartman
5096aedc f2189c47

+9 -21
+9 -21
drivers/usb/core/driver.c
··· 814 814 * The caller must hold @intf's device's lock, but not its pm_mutex 815 815 * and not @intf->dev.sem. 816 816 * 817 - * FIXME: The caller must block system sleep transitions. 817 + * Note: Rebinds will be skipped if a system sleep transition is in 818 + * progress and the PM "complete" callback hasn't occurred yet. 818 819 */ 819 820 void usb_rebind_intf(struct usb_interface *intf) 820 821 { ··· 831 830 } 832 831 833 832 /* Try to rebind the interface */ 834 - intf->needs_binding = 0; 835 - rc = device_attach(&intf->dev); 836 - if (rc < 0) 837 - dev_warn(&intf->dev, "rebind failed: %d\n", rc); 833 + if (intf->dev.power.status == DPM_ON) { 834 + intf->needs_binding = 0; 835 + rc = device_attach(&intf->dev); 836 + if (rc < 0) 837 + dev_warn(&intf->dev, "rebind failed: %d\n", rc); 838 + } 838 839 } 839 840 840 841 #ifdef CONFIG_PM ··· 848 845 * or rebind interfaces that have been unbound, according to @action. 849 846 * 850 847 * The caller must hold @udev's device lock. 851 - * FIXME: For rebinds, the caller must block system sleep transitions. 852 848 */ 853 849 static void do_unbind_rebind(struct usb_device *udev, int action) 854 850 { ··· 869 867 } 870 868 break; 871 869 case DO_REBIND: 872 - if (intf->needs_binding) { 873 - 874 - /* FIXME: The next line is needed because we are going to probe 875 - * the interface, but as far as the PM core is concerned the 876 - * interface is still suspended. The problem wouldn't exist 877 - * if we could rebind the interface during the interface's own 878 - * resume() call, but at the time the usb_device isn't locked! 879 - * 880 - * The real solution will be to carry this out during the device's 881 - * complete() callback. Until that is implemented, we have to 882 - * use this hack. 883 - */ 884 - // intf->dev.power.sleeping = 0; 885 - 870 + if (intf->needs_binding) 886 871 usb_rebind_intf(intf); 887 - } 888 872 break; 889 873 } 890 874 }