patch/piuio-exit: Bugfix when using with more usb devices than just piuio

If you also have the piubtn connected, it will be opened as well, hitting
the open section in the module. It did forward everything correctly, but
the warning didn't make any sense because the same device was not opened
again. Re-work the code to create a meaningful flow. Also return the open
handle if it ever happens that the device gets re-opened without being
closed.
This commit is contained in:
icex2
2021-03-19 12:43:19 +01:00
parent 36736c8a7c
commit c2ee8c0583
+12 -10
View File
@@ -26,20 +26,22 @@ static enum cnh_result patch_piuio_exit_usbhook(struct cnh_usbhook_irp *irp)
switch (irp->op) {
case CNH_USBHOOK_IRP_OP_OPEN:
{
if (_patch_piuio_exit_usb_handle) {
log_warn("Already detected PIUIO previously, ignore re-detection?");
result = cnh_usbhook_invoke_next(irp);
break;
}
if (irp->open_usb_dev->descriptor.idVendor == PIUIO_DRV_VID &&
irp->open_usb_dev->descriptor.idProduct == PIUIO_DRV_PID) {
log_info("Detected PIUIO");
result = cnh_usbhook_invoke_next(irp);
if (_patch_piuio_exit_usb_handle) {
log_warn("Already detected PIUIO previously, ignore re-detection?");
if (result == CNH_RESULT_SUCCESS) {
_patch_piuio_exit_usb_handle = irp->handle;
irp->handle = _patch_piuio_exit_usb_handle;
result = CNH_RESULT_SUCCESS;
} else {
log_info("Detected PIUIO");
result = cnh_usbhook_invoke_next(irp);
if (result == CNH_RESULT_SUCCESS) {
_patch_piuio_exit_usb_handle = irp->handle;
}
}
} else {
result = cnh_usbhook_invoke_next(irp);