forked from cezanne/usbip-win
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix BSOD occurred when detaching a busy device
Old plugout was prone to incur BSOD when a very busy device is detached. Fiio device suffers from such the problem(see comment in cezanne#222). Indeed, there was no locking between vusb I/O and plugout. To resolve this issue, get/put for vusb has been introduced with a reference count.
- Loading branch information
Showing
13 changed files
with
154 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include "vhci_driver.h" | ||
#include "vhci_vusb.tmh" | ||
|
||
pctx_vusb_t | ||
get_vusb(pctx_vhci_t vhci, ULONG port) | ||
{ | ||
pctx_vusb_t vusb; | ||
|
||
WdfSpinLockAcquire(vhci->spin_lock); | ||
|
||
vusb = vhci->vusbs[port]; | ||
if (vusb == NULL || vusb->invalid) { | ||
WdfSpinLockRelease(vhci->spin_lock); | ||
return NULL; | ||
} | ||
vusb->refcnt++; | ||
|
||
WdfSpinLockRelease(vhci->spin_lock); | ||
|
||
return vusb; | ||
} | ||
|
||
pctx_vusb_t | ||
get_vusb_by_req(WDFREQUEST req) | ||
{ | ||
pctx_safe_vusb_t svusb; | ||
|
||
svusb = TO_SAFE_VUSB_FROM_REQ(req); | ||
return get_vusb(svusb->vhci, svusb->port); | ||
} | ||
|
||
void | ||
put_vusb(pctx_vusb_t vusb) | ||
{ | ||
pctx_vhci_t vhci = vusb->vhci; | ||
|
||
WdfSpinLockAcquire(vhci->spin_lock); | ||
|
||
ASSERT(vusb->refcnt > 0); | ||
vusb->refcnt--; | ||
if (vusb->refcnt == 0 && vusb->invalid) { | ||
NTSTATUS status; | ||
|
||
vhci->vusbs[vusb->port] = NULL; | ||
WdfSpinLockRelease(vhci->spin_lock); | ||
|
||
status = UdecxUsbDevicePlugOutAndDelete(vusb->ude_usbdev); | ||
if (NT_ERROR(status)) { | ||
TRD(PLUGIN, "failed to plug out: %!STATUS!", status); | ||
} | ||
} | ||
else { | ||
WdfSpinLockRelease(vhci->spin_lock); | ||
} | ||
} |
Oops, something went wrong.