From 862933f9a7c84d33454657f89bef9e281589b13f Mon Sep 17 00:00:00 2001 From: KyungWoon Cho Date: Sun, 10 Jan 2021 21:24:29 +0900 Subject: [PATCH] more smooth cleanup for vusb for vhci(ude) If setting interface fails for a being detached device, vusb does not be cleaned up. So, dynamic interface setting is avoided for an invalidated device. --- driver/vhci_ude/vhci_ep.c | 8 +++++++- driver/vhci_ude/vhci_urbr.c | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/driver/vhci_ude/vhci_ep.c b/driver/vhci_ude/vhci_ep.c index 8509553b..45462557 100644 --- a/driver/vhci_ude/vhci_ep.c +++ b/driver/vhci_ude/vhci_ep.c @@ -215,7 +215,13 @@ ep_configure(_In_ UDECXUSBDEVICE udev, _In_ WDFREQUEST req, _In_ PUDECX_ENDPOINT status = submit_req_select(vusb->ep_default, req, 1, params->NewConfigurationValue, 0, 0); break; case UdecxEndpointsConfigureTypeInterfaceSettingChange: - status = set_intf_for_ep(vusb, req, params); + /* + * When a device is being detached, set_intf for the invalidated device is avoided. + * Error status for set_intf seems to disturb detaching. + */ + if (!vusb->invalid) { + status = set_intf_for_ep(vusb, req, params); + } break; case UdecxEndpointsConfigureTypeEndpointsReleasedOnly: break; diff --git a/driver/vhci_ude/vhci_urbr.c b/driver/vhci_ude/vhci_urbr.c index 32728337..21c225dd 100644 --- a/driver/vhci_ude/vhci_urbr.c +++ b/driver/vhci_ude/vhci_urbr.c @@ -194,6 +194,12 @@ submit_urbr(purb_req_t urbr) WdfSpinLockAcquire(vusb->spin_lock); + if (vusb->invalid) { + WdfSpinLockRelease(vusb->spin_lock); + TRD(URBR, "failed to submit urbr: invalidated vusb"); + return STATUS_DEVICE_NOT_CONNECTED; + } + if (vusb->urbr_sent_partial || vusb->pending_req_read == NULL) { if (urbr->type == URBR_TYPE_URB) { status = WdfRequestMarkCancelableEx(urbr->req, urbr_cancelled);