diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2020-07-10 22:04:12 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-07-10 22:04:12 +0300 |
| commit | 675cad6d635be00c166b5ce23a79e32edd694bc8 (patch) | |
| tree | 6c679e543dbf55e87eb7946a4b3b972e59dc3984 /hid-tm.h | |
| parent | 6faa9ae6a8cf242679ce4e493a66fcb31d231c09 (diff) | |
| parent | 4d82a0fdfb95cdea2fd904c3ee33c1c6f603d153 (diff) | |
| download | hid-tmff2-675cad6d635be00c166b5ce23a79e32edd694bc8.tar.gz hid-tmff2-675cad6d635be00c166b5ce23a79e32edd694bc8.zip | |
Merge pull request #2 from Kimplul/memory
Memory
Diffstat (limited to 'hid-tm.h')
| -rw-r--r-- | hid-tm.h | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/hid-tm.h b/hid-tm.h new file mode 100644 index 0000000..e0117ae --- /dev/null +++ b/hid-tm.h @@ -0,0 +1,48 @@ +#include <linux/hid.h> +#include <linux/usb.h> +#include <linux/input.h> +#include <linux/slab.h> +#include <linux/module.h> + +#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; +} |
