usb: core: resume clears needs_altsetting0 even on failure
Hi Greg, Alan,
I hit a corner case in usb_resume_interface(). It needs a device that fails SET_INTERFACE(0) both when the driver is unbound and again at resume, so it may not be worth fixing.
needs_altsetting0 is handled in three places. usb_unbind_interface() sets it when the switch to altsetting 0 fails, and usb_probe_interface() clears it only after the switch succeeds. But usb_resume_interface() clears it even when its deferred usb_set_interface(..., 0) fails. probe then skips the switch, and the next driver binds with the interface still at the old altsetting.
On v7.3 with raw-gadget and dummy_hcd, the gadget stalled SET_INTERFACE(0) at unbind and at resume. usbtest then bound to the interface while it was at altsetting 1, and its URB failed with -ENOENT. The code is unchanged in next-20261113.
Clearing the flag only on success, as probe does, fixes it:
- usb_set_interface(udev, intf->altsetting[0]. - desc.bInterfaceNumber, 0); - intf->needs_altsetting0 = 0; + if (!usb_set_interface(udev, intf->altsetting[0]. + desc.bInterfaceNumber, 0)) + intf->needs_altsetting0 = 0;
With the version I tested, which also logged the error, probe retried the switch and refused to bind while the gadget kept stalling, and normal resume was unchanged. I can send a patch if you want one.
Thanks,
Cheng Yongkang
Greg Kroah-Hartman
maintainerQuoted 5 lines · Cheng Yongkang
Hi Greg, Alan,
I hit a corner case in
usb_resume_interface(). It needs a device that failsSET_INTERFACE(0)both when the driver is unbound and again at resume, so it may not be worth fixing.
<snip>
As your "tool" found these, it can also make a proposed patch and test it for them as well. Please do so, don't just send "empty" messages that claim a problem is found by a static analysis program.
thanks,
greg k-h