Skip to contentSkip to conversation

usb-host: reset the open retry count after a successful open

PATCH New Junjie Cao 1 participant 1 message Oct 28

lore
Share & tools
lore

Junjie Cao

author
#0 lore raw

PATCH 1/1 usb-host: reset the open retry count after a successful open

usb_host_auto_check() gives up on a matching device once three opens have failed, and clears the failure count only when a scan finds no matching device at all. A device that re-enumerates, e.g. after a firmware reboot, is closed on NO_DEVICE and usb_host_close() rescans at once, while libusb still lists the old address: that open fails and counts, the next 2 s scan opens the new address, and nothing clears the count. After the third such cycle the device is skipped until a scan finds it absent or the usb-host device is re-added.

Clear the count once an open succeeds. A device that cannot be opened at all still stops after three attempts.

The source-level fixture attached to #4673 reproduces the same sequence; its remaining cases expect a failure budget per enumerated device, which this change does not add.

Fixes 3ee886c5ba77 ("usb-host: limit open retries")

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/4631

---
The source-level fixture attached to #4673: 15 tests, 7 failures on master d29412cca5, 5 with this change. The two reconnect scenarios pass (repeated-reconnects, success-resets-own-budget). Of the other five, four expect a failure budget per enumerated device and one expects a libusb_get_device_list() error not to reset the count; both are outside this change.

Farid's attached patch resets the count inside usb_host_open(); this one keeps it next to the failure count in usb_host_auto_check().

 hw/usb/host-libusb.c | 1 +
 1 file changed, 1 insertion(+)
hw/usb/host-libusb.c +1 -0
index 8f7ced95cf..5a369e2ebf 100644
@@ -1924,6 +1924,7 @@ static void usb_host_auto_check(void *unused)
                     s->errcount++;
                     continue;
                 }
+                s->errcount = 0;
                 break;
             }
         }
Signature · 1 line
2.43.0