From db12c7bead4154929668badaade14db135dab6d9 Mon Sep 17 00:00:00 2001 From: kimi Date: Wed, 8 Jul 2020 11:17:48 -0400 Subject: initial commit for memory --- hid-tm.h | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 hid-tm.h (limited to 'hid-tm.h') diff --git a/hid-tm.h b/hid-tm.h new file mode 100644 index 0000000..17cc741 --- /dev/null +++ b/hid-tm.h @@ -0,0 +1,49 @@ +#include +#include +#include +#include +#include + +#define USB_VENDOR_ID_THRUSTMASTER 0x044f + +struct api_context { + struct completion done; + int status; +}; + +struct api_context ctx; + +int usb_start_wait_urb(struct urb *urb, int timeout, int *actual_length) +{ + + unsigned long expire; + int retval; + + init_completion(&ctx.done); + urb->context = &ctx; + urb->actual_length = 0; + retval = usb_submit_urb(urb, GFP_ATOMIC); + if (unlikely(retval)) + goto out; + + expire = timeout ? msecs_to_jiffies(timeout) : MAX_SCHEDULE_TIMEOUT; + if (!wait_for_completion_timeout(&ctx.done, expire)) { + usb_kill_urb(urb); + retval = (ctx.status == -ENOENT ? -ETIMEDOUT : ctx.status); + + dev_dbg(&urb->dev->dev, + "%s timed out on ep%d%s len=%u/%u\n", + current->comm, + usb_endpoint_num(&urb->ep->desc), + usb_urb_dir_in(urb) ? "in" : "out", + urb->actual_length, + urb->transfer_buffer_length); + } else + retval = ctx.status; +out: + if (actual_length) + *actual_length = urb->actual_length; + + usb_free_urb(urb); + return retval; +} -- cgit v1.3