David Herrmann | 1ccd7a2 | 2012-06-10 15:16:13 +0200 | [diff] [blame] | 1 | /* |
| 2 | * User-space I/O driver support for HID subsystem |
| 3 | * Copyright (c) 2012 David Herrmann |
| 4 | */ |
| 5 | |
| 6 | /* |
| 7 | * This program is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License as published by the Free |
| 9 | * Software Foundation; either version 2 of the License, or (at your option) |
| 10 | * any later version. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/atomic.h> |
Dmitry Torokhov | befde02 | 2013-02-18 11:26:11 +0100 | [diff] [blame] | 14 | #include <linux/compat.h> |
Eric Biggers | cf7de65 | 2018-11-14 13:55:09 -0800 | [diff] [blame] | 15 | #include <linux/cred.h> |
David Herrmann | 1ccd7a2 | 2012-06-10 15:16:13 +0200 | [diff] [blame] | 16 | #include <linux/device.h> |
| 17 | #include <linux/fs.h> |
| 18 | #include <linux/hid.h> |
| 19 | #include <linux/input.h> |
| 20 | #include <linux/miscdevice.h> |
| 21 | #include <linux/module.h> |
| 22 | #include <linux/mutex.h> |
| 23 | #include <linux/poll.h> |
| 24 | #include <linux/sched.h> |
| 25 | #include <linux/spinlock.h> |
| 26 | #include <linux/uhid.h> |
| 27 | #include <linux/wait.h> |
| 28 | |
| 29 | #define UHID_NAME "uhid" |
David Herrmann | ace3d86 | 2012-06-10 15:16:14 +0200 | [diff] [blame] | 30 | #define UHID_BUFSIZE 32 |
| 31 | |
| 32 | struct uhid_device { |
David Herrmann | d937ae5 | 2012-06-10 15:16:16 +0200 | [diff] [blame] | 33 | struct mutex devlock; |
David Herrmann | d365c6c | 2012-06-10 15:16:18 +0200 | [diff] [blame] | 34 | bool running; |
| 35 | |
| 36 | __u8 *rd_data; |
| 37 | uint rd_size; |
| 38 | |
David Herrmann | ace3d86 | 2012-06-10 15:16:14 +0200 | [diff] [blame] | 39 | struct hid_device *hid; |
David Herrmann | 6664ef7 | 2012-06-10 15:16:17 +0200 | [diff] [blame] | 40 | struct uhid_event input_buf; |
David Herrmann | ace3d86 | 2012-06-10 15:16:14 +0200 | [diff] [blame] | 41 | |
| 42 | wait_queue_head_t waitq; |
| 43 | spinlock_t qlock; |
| 44 | __u8 head; |
| 45 | __u8 tail; |
| 46 | struct uhid_event *outq[UHID_BUFSIZE]; |
David Herrmann | fcfcf0d | 2012-06-10 15:16:25 +0200 | [diff] [blame] | 47 | |
David Herrmann | 8cad5b0 | 2014-07-29 17:14:19 +0200 | [diff] [blame] | 48 | /* blocking GET_REPORT support; state changes protected by qlock */ |
David Herrmann | fcfcf0d | 2012-06-10 15:16:25 +0200 | [diff] [blame] | 49 | struct mutex report_lock; |
| 50 | wait_queue_head_t report_wait; |
David Herrmann | 5942b84 | 2014-07-29 17:14:20 +0200 | [diff] [blame] | 51 | bool report_running; |
David Herrmann | 8cad5b0 | 2014-07-29 17:14:19 +0200 | [diff] [blame] | 52 | u32 report_id; |
David Herrmann | 11c2215 | 2014-07-29 17:14:24 +0200 | [diff] [blame] | 53 | u32 report_type; |
David Herrmann | fcfcf0d | 2012-06-10 15:16:25 +0200 | [diff] [blame] | 54 | struct uhid_event report_buf; |
Roderick Colenbrander | 67f8ecc | 2016-05-18 13:11:09 -0700 | [diff] [blame] | 55 | struct work_struct worker; |
David Herrmann | ace3d86 | 2012-06-10 15:16:14 +0200 | [diff] [blame] | 56 | }; |
David Herrmann | 1ccd7a2 | 2012-06-10 15:16:13 +0200 | [diff] [blame] | 57 | |
| 58 | static struct miscdevice uhid_misc; |
| 59 | |
Roderick Colenbrander | 67f8ecc | 2016-05-18 13:11:09 -0700 | [diff] [blame] | 60 | static void uhid_device_add_worker(struct work_struct *work) |
| 61 | { |
| 62 | struct uhid_device *uhid = container_of(work, struct uhid_device, worker); |
| 63 | int ret; |
| 64 | |
| 65 | ret = hid_add_device(uhid->hid); |
| 66 | if (ret) { |
| 67 | hid_err(uhid->hid, "Cannot register HID device: error %d\n", ret); |
| 68 | |
| 69 | hid_destroy_device(uhid->hid); |
| 70 | uhid->hid = NULL; |
| 71 | uhid->running = false; |
| 72 | } |
| 73 | } |
| 74 | |
David Herrmann | ace3d86 | 2012-06-10 15:16:14 +0200 | [diff] [blame] | 75 | static void uhid_queue(struct uhid_device *uhid, struct uhid_event *ev) |
| 76 | { |
| 77 | __u8 newhead; |
| 78 | |
| 79 | newhead = (uhid->head + 1) % UHID_BUFSIZE; |
| 80 | |
| 81 | if (newhead != uhid->tail) { |
| 82 | uhid->outq[uhid->head] = ev; |
| 83 | uhid->head = newhead; |
| 84 | wake_up_interruptible(&uhid->waitq); |
| 85 | } else { |
| 86 | hid_warn(uhid->hid, "Output queue is full\n"); |
| 87 | kfree(ev); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | static int uhid_queue_event(struct uhid_device *uhid, __u32 event) |
| 92 | { |
| 93 | unsigned long flags; |
| 94 | struct uhid_event *ev; |
| 95 | |
| 96 | ev = kzalloc(sizeof(*ev), GFP_KERNEL); |
| 97 | if (!ev) |
| 98 | return -ENOMEM; |
| 99 | |
| 100 | ev->type = event; |
| 101 | |
| 102 | spin_lock_irqsave(&uhid->qlock, flags); |
| 103 | uhid_queue(uhid, ev); |
| 104 | spin_unlock_irqrestore(&uhid->qlock, flags); |
| 105 | |
| 106 | return 0; |
| 107 | } |
| 108 | |
David Herrmann | d365c6c | 2012-06-10 15:16:18 +0200 | [diff] [blame] | 109 | static int uhid_hid_start(struct hid_device *hid) |
| 110 | { |
David Herrmann | ec4b7de | 2012-06-10 15:16:21 +0200 | [diff] [blame] | 111 | struct uhid_device *uhid = hid->driver_data; |
David Herrmann | c2b2f16 | 2014-07-29 17:14:25 +0200 | [diff] [blame] | 112 | struct uhid_event *ev; |
| 113 | unsigned long flags; |
David Herrmann | ec4b7de | 2012-06-10 15:16:21 +0200 | [diff] [blame] | 114 | |
David Herrmann | c2b2f16 | 2014-07-29 17:14:25 +0200 | [diff] [blame] | 115 | ev = kzalloc(sizeof(*ev), GFP_KERNEL); |
| 116 | if (!ev) |
| 117 | return -ENOMEM; |
| 118 | |
| 119 | ev->type = UHID_START; |
| 120 | |
| 121 | if (hid->report_enum[HID_FEATURE_REPORT].numbered) |
| 122 | ev->u.start.dev_flags |= UHID_DEV_NUMBERED_FEATURE_REPORTS; |
| 123 | if (hid->report_enum[HID_OUTPUT_REPORT].numbered) |
| 124 | ev->u.start.dev_flags |= UHID_DEV_NUMBERED_OUTPUT_REPORTS; |
| 125 | if (hid->report_enum[HID_INPUT_REPORT].numbered) |
| 126 | ev->u.start.dev_flags |= UHID_DEV_NUMBERED_INPUT_REPORTS; |
| 127 | |
| 128 | spin_lock_irqsave(&uhid->qlock, flags); |
| 129 | uhid_queue(uhid, ev); |
| 130 | spin_unlock_irqrestore(&uhid->qlock, flags); |
| 131 | |
| 132 | return 0; |
David Herrmann | d365c6c | 2012-06-10 15:16:18 +0200 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | static void uhid_hid_stop(struct hid_device *hid) |
| 136 | { |
David Herrmann | ec4b7de | 2012-06-10 15:16:21 +0200 | [diff] [blame] | 137 | struct uhid_device *uhid = hid->driver_data; |
| 138 | |
| 139 | hid->claimed = 0; |
| 140 | uhid_queue_event(uhid, UHID_STOP); |
David Herrmann | d365c6c | 2012-06-10 15:16:18 +0200 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | static int uhid_hid_open(struct hid_device *hid) |
| 144 | { |
David Herrmann | e719147 | 2012-06-10 15:16:22 +0200 | [diff] [blame] | 145 | struct uhid_device *uhid = hid->driver_data; |
| 146 | |
| 147 | return uhid_queue_event(uhid, UHID_OPEN); |
David Herrmann | d365c6c | 2012-06-10 15:16:18 +0200 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | static void uhid_hid_close(struct hid_device *hid) |
| 151 | { |
David Herrmann | e719147 | 2012-06-10 15:16:22 +0200 | [diff] [blame] | 152 | struct uhid_device *uhid = hid->driver_data; |
| 153 | |
| 154 | uhid_queue_event(uhid, UHID_CLOSE); |
David Herrmann | d365c6c | 2012-06-10 15:16:18 +0200 | [diff] [blame] | 155 | } |
| 156 | |
David Herrmann | d365c6c | 2012-06-10 15:16:18 +0200 | [diff] [blame] | 157 | static int uhid_hid_parse(struct hid_device *hid) |
| 158 | { |
David Herrmann | 037c061 | 2012-06-10 15:16:20 +0200 | [diff] [blame] | 159 | struct uhid_device *uhid = hid->driver_data; |
| 160 | |
| 161 | return hid_parse_report(hid, uhid->rd_data, uhid->rd_size); |
David Herrmann | d365c6c | 2012-06-10 15:16:18 +0200 | [diff] [blame] | 162 | } |
| 163 | |
David Herrmann | 11c2215 | 2014-07-29 17:14:24 +0200 | [diff] [blame] | 164 | /* must be called with report_lock held */ |
| 165 | static int __uhid_report_queue_and_wait(struct uhid_device *uhid, |
| 166 | struct uhid_event *ev, |
| 167 | __u32 *report_id) |
Jiri Kosina | 289a716 | 2014-02-17 14:49:34 +0100 | [diff] [blame] | 168 | { |
Jiri Kosina | 289a716 | 2014-02-17 14:49:34 +0100 | [diff] [blame] | 169 | unsigned long flags; |
| 170 | int ret; |
Jiri Kosina | 289a716 | 2014-02-17 14:49:34 +0100 | [diff] [blame] | 171 | |
| 172 | spin_lock_irqsave(&uhid->qlock, flags); |
David Herrmann | 11c2215 | 2014-07-29 17:14:24 +0200 | [diff] [blame] | 173 | *report_id = ++uhid->report_id; |
Benjamin Tissoires | 8493ecc | 2014-10-01 11:59:47 -0400 | [diff] [blame] | 174 | uhid->report_type = ev->type + 1; |
David Herrmann | 5942b84 | 2014-07-29 17:14:20 +0200 | [diff] [blame] | 175 | uhid->report_running = true; |
Jiri Kosina | 289a716 | 2014-02-17 14:49:34 +0100 | [diff] [blame] | 176 | uhid_queue(uhid, ev); |
| 177 | spin_unlock_irqrestore(&uhid->qlock, flags); |
| 178 | |
| 179 | ret = wait_event_interruptible_timeout(uhid->report_wait, |
David Herrmann | 5942b84 | 2014-07-29 17:14:20 +0200 | [diff] [blame] | 180 | !uhid->report_running || !uhid->running, |
| 181 | 5 * HZ); |
David Herrmann | 11c2215 | 2014-07-29 17:14:24 +0200 | [diff] [blame] | 182 | if (!ret || !uhid->running || uhid->report_running) |
Jiri Kosina | 289a716 | 2014-02-17 14:49:34 +0100 | [diff] [blame] | 183 | ret = -EIO; |
David Herrmann | 11c2215 | 2014-07-29 17:14:24 +0200 | [diff] [blame] | 184 | else if (ret < 0) |
Jiri Kosina | 289a716 | 2014-02-17 14:49:34 +0100 | [diff] [blame] | 185 | ret = -ERESTARTSYS; |
David Herrmann | 11c2215 | 2014-07-29 17:14:24 +0200 | [diff] [blame] | 186 | else |
| 187 | ret = 0; |
Jiri Kosina | 289a716 | 2014-02-17 14:49:34 +0100 | [diff] [blame] | 188 | |
David Herrmann | 5942b84 | 2014-07-29 17:14:20 +0200 | [diff] [blame] | 189 | uhid->report_running = false; |
Jiri Kosina | 289a716 | 2014-02-17 14:49:34 +0100 | [diff] [blame] | 190 | |
David Herrmann | 11c2215 | 2014-07-29 17:14:24 +0200 | [diff] [blame] | 191 | return ret; |
| 192 | } |
| 193 | |
| 194 | static void uhid_report_wake_up(struct uhid_device *uhid, u32 id, |
| 195 | const struct uhid_event *ev) |
| 196 | { |
| 197 | unsigned long flags; |
| 198 | |
| 199 | spin_lock_irqsave(&uhid->qlock, flags); |
| 200 | |
| 201 | /* id for old report; drop it silently */ |
| 202 | if (uhid->report_type != ev->type || uhid->report_id != id) |
| 203 | goto unlock; |
| 204 | if (!uhid->report_running) |
| 205 | goto unlock; |
| 206 | |
| 207 | memcpy(&uhid->report_buf, ev, sizeof(*ev)); |
| 208 | uhid->report_running = false; |
| 209 | wake_up_interruptible(&uhid->report_wait); |
| 210 | |
| 211 | unlock: |
| 212 | spin_unlock_irqrestore(&uhid->qlock, flags); |
| 213 | } |
| 214 | |
| 215 | static int uhid_hid_get_report(struct hid_device *hid, unsigned char rnum, |
| 216 | u8 *buf, size_t count, u8 rtype) |
| 217 | { |
| 218 | struct uhid_device *uhid = hid->driver_data; |
| 219 | struct uhid_get_report_reply_req *req; |
| 220 | struct uhid_event *ev; |
| 221 | int ret; |
| 222 | |
| 223 | if (!uhid->running) |
| 224 | return -EIO; |
| 225 | |
| 226 | ev = kzalloc(sizeof(*ev), GFP_KERNEL); |
| 227 | if (!ev) |
| 228 | return -ENOMEM; |
| 229 | |
| 230 | ev->type = UHID_GET_REPORT; |
| 231 | ev->u.get_report.rnum = rnum; |
| 232 | ev->u.get_report.rtype = rtype; |
| 233 | |
| 234 | ret = mutex_lock_interruptible(&uhid->report_lock); |
| 235 | if (ret) { |
| 236 | kfree(ev); |
| 237 | return ret; |
| 238 | } |
| 239 | |
| 240 | /* this _always_ takes ownership of @ev */ |
| 241 | ret = __uhid_report_queue_and_wait(uhid, ev, &ev->u.get_report.id); |
| 242 | if (ret) |
| 243 | goto unlock; |
| 244 | |
| 245 | req = &uhid->report_buf.u.get_report_reply; |
| 246 | if (req->err) { |
| 247 | ret = -EIO; |
| 248 | } else { |
| 249 | ret = min3(count, (size_t)req->size, (size_t)UHID_DATA_MAX); |
| 250 | memcpy(buf, req->data, ret); |
| 251 | } |
| 252 | |
Jiri Kosina | 289a716 | 2014-02-17 14:49:34 +0100 | [diff] [blame] | 253 | unlock: |
| 254 | mutex_unlock(&uhid->report_lock); |
David Herrmann | 11c2215 | 2014-07-29 17:14:24 +0200 | [diff] [blame] | 255 | return ret; |
| 256 | } |
| 257 | |
| 258 | static int uhid_hid_set_report(struct hid_device *hid, unsigned char rnum, |
| 259 | const u8 *buf, size_t count, u8 rtype) |
| 260 | { |
| 261 | struct uhid_device *uhid = hid->driver_data; |
| 262 | struct uhid_event *ev; |
| 263 | int ret; |
| 264 | |
| 265 | if (!uhid->running || count > UHID_DATA_MAX) |
| 266 | return -EIO; |
| 267 | |
| 268 | ev = kzalloc(sizeof(*ev), GFP_KERNEL); |
| 269 | if (!ev) |
| 270 | return -ENOMEM; |
| 271 | |
| 272 | ev->type = UHID_SET_REPORT; |
| 273 | ev->u.set_report.rnum = rnum; |
| 274 | ev->u.set_report.rtype = rtype; |
| 275 | ev->u.set_report.size = count; |
| 276 | memcpy(ev->u.set_report.data, buf, count); |
| 277 | |
| 278 | ret = mutex_lock_interruptible(&uhid->report_lock); |
| 279 | if (ret) { |
| 280 | kfree(ev); |
| 281 | return ret; |
| 282 | } |
| 283 | |
| 284 | /* this _always_ takes ownership of @ev */ |
| 285 | ret = __uhid_report_queue_and_wait(uhid, ev, &ev->u.set_report.id); |
| 286 | if (ret) |
| 287 | goto unlock; |
| 288 | |
| 289 | if (uhid->report_buf.u.set_report_reply.err) |
| 290 | ret = -EIO; |
| 291 | else |
| 292 | ret = count; |
| 293 | |
| 294 | unlock: |
| 295 | mutex_unlock(&uhid->report_lock); |
| 296 | return ret; |
Jiri Kosina | 289a716 | 2014-02-17 14:49:34 +0100 | [diff] [blame] | 297 | } |
| 298 | |
David Herrmann | 7c4003b | 2014-07-29 17:14:23 +0200 | [diff] [blame] | 299 | static int uhid_hid_raw_request(struct hid_device *hid, unsigned char reportnum, |
| 300 | __u8 *buf, size_t len, unsigned char rtype, |
| 301 | int reqtype) |
| 302 | { |
David Herrmann | 11c2215 | 2014-07-29 17:14:24 +0200 | [diff] [blame] | 303 | u8 u_rtype; |
| 304 | |
| 305 | switch (rtype) { |
| 306 | case HID_FEATURE_REPORT: |
| 307 | u_rtype = UHID_FEATURE_REPORT; |
| 308 | break; |
| 309 | case HID_OUTPUT_REPORT: |
| 310 | u_rtype = UHID_OUTPUT_REPORT; |
| 311 | break; |
| 312 | case HID_INPUT_REPORT: |
| 313 | u_rtype = UHID_INPUT_REPORT; |
| 314 | break; |
| 315 | default: |
| 316 | return -EINVAL; |
| 317 | } |
| 318 | |
David Herrmann | 7c4003b | 2014-07-29 17:14:23 +0200 | [diff] [blame] | 319 | switch (reqtype) { |
| 320 | case HID_REQ_GET_REPORT: |
David Herrmann | 11c2215 | 2014-07-29 17:14:24 +0200 | [diff] [blame] | 321 | return uhid_hid_get_report(hid, reportnum, buf, len, u_rtype); |
David Herrmann | 7c4003b | 2014-07-29 17:14:23 +0200 | [diff] [blame] | 322 | case HID_REQ_SET_REPORT: |
David Herrmann | 11c2215 | 2014-07-29 17:14:24 +0200 | [diff] [blame] | 323 | return uhid_hid_set_report(hid, reportnum, buf, len, u_rtype); |
David Herrmann | 7c4003b | 2014-07-29 17:14:23 +0200 | [diff] [blame] | 324 | default: |
| 325 | return -EIO; |
| 326 | } |
| 327 | } |
| 328 | |
David Herrmann | d365c6c | 2012-06-10 15:16:18 +0200 | [diff] [blame] | 329 | static int uhid_hid_output_raw(struct hid_device *hid, __u8 *buf, size_t count, |
| 330 | unsigned char report_type) |
| 331 | { |
David Herrmann | 3b3baa8 | 2012-06-10 15:16:24 +0200 | [diff] [blame] | 332 | struct uhid_device *uhid = hid->driver_data; |
| 333 | __u8 rtype; |
| 334 | unsigned long flags; |
| 335 | struct uhid_event *ev; |
| 336 | |
| 337 | switch (report_type) { |
| 338 | case HID_FEATURE_REPORT: |
| 339 | rtype = UHID_FEATURE_REPORT; |
| 340 | break; |
| 341 | case HID_OUTPUT_REPORT: |
| 342 | rtype = UHID_OUTPUT_REPORT; |
| 343 | break; |
| 344 | default: |
| 345 | return -EINVAL; |
| 346 | } |
| 347 | |
| 348 | if (count < 1 || count > UHID_DATA_MAX) |
| 349 | return -EINVAL; |
| 350 | |
| 351 | ev = kzalloc(sizeof(*ev), GFP_KERNEL); |
| 352 | if (!ev) |
| 353 | return -ENOMEM; |
| 354 | |
| 355 | ev->type = UHID_OUTPUT; |
| 356 | ev->u.output.size = count; |
| 357 | ev->u.output.rtype = rtype; |
| 358 | memcpy(ev->u.output.data, buf, count); |
| 359 | |
| 360 | spin_lock_irqsave(&uhid->qlock, flags); |
| 361 | uhid_queue(uhid, ev); |
| 362 | spin_unlock_irqrestore(&uhid->qlock, flags); |
| 363 | |
| 364 | return count; |
David Herrmann | d365c6c | 2012-06-10 15:16:18 +0200 | [diff] [blame] | 365 | } |
| 366 | |
Frank Praznik | 596cfdd | 2014-01-22 13:49:43 -0500 | [diff] [blame] | 367 | static int uhid_hid_output_report(struct hid_device *hid, __u8 *buf, |
| 368 | size_t count) |
| 369 | { |
Benjamin Tissoires | 41abfb3 | 2014-02-10 12:58:46 -0500 | [diff] [blame] | 370 | return uhid_hid_output_raw(hid, buf, count, HID_OUTPUT_REPORT); |
Frank Praznik | 596cfdd | 2014-01-22 13:49:43 -0500 | [diff] [blame] | 371 | } |
| 372 | |
Jason Gerecke | fc2237a | 2017-07-24 09:46:18 -0700 | [diff] [blame] | 373 | struct hid_ll_driver uhid_hid_driver = { |
David Herrmann | d365c6c | 2012-06-10 15:16:18 +0200 | [diff] [blame] | 374 | .start = uhid_hid_start, |
| 375 | .stop = uhid_hid_stop, |
| 376 | .open = uhid_hid_open, |
| 377 | .close = uhid_hid_close, |
David Herrmann | d365c6c | 2012-06-10 15:16:18 +0200 | [diff] [blame] | 378 | .parse = uhid_hid_parse, |
David Herrmann | 7c4003b | 2014-07-29 17:14:23 +0200 | [diff] [blame] | 379 | .raw_request = uhid_hid_raw_request, |
Frank Praznik | 596cfdd | 2014-01-22 13:49:43 -0500 | [diff] [blame] | 380 | .output_report = uhid_hid_output_report, |
David Herrmann | d365c6c | 2012-06-10 15:16:18 +0200 | [diff] [blame] | 381 | }; |
Jason Gerecke | fc2237a | 2017-07-24 09:46:18 -0700 | [diff] [blame] | 382 | EXPORT_SYMBOL_GPL(uhid_hid_driver); |
David Herrmann | d365c6c | 2012-06-10 15:16:18 +0200 | [diff] [blame] | 383 | |
Dmitry Torokhov | befde02 | 2013-02-18 11:26:11 +0100 | [diff] [blame] | 384 | #ifdef CONFIG_COMPAT |
| 385 | |
| 386 | /* Apparently we haven't stepped on these rakes enough times yet. */ |
| 387 | struct uhid_create_req_compat { |
| 388 | __u8 name[128]; |
| 389 | __u8 phys[64]; |
| 390 | __u8 uniq[64]; |
| 391 | |
| 392 | compat_uptr_t rd_data; |
| 393 | __u16 rd_size; |
| 394 | |
| 395 | __u16 bus; |
| 396 | __u32 vendor; |
| 397 | __u32 product; |
| 398 | __u32 version; |
| 399 | __u32 country; |
| 400 | } __attribute__((__packed__)); |
| 401 | |
| 402 | static int uhid_event_from_user(const char __user *buffer, size_t len, |
| 403 | struct uhid_event *event) |
| 404 | { |
Andy Lutomirski | 7365abb | 2016-03-22 14:25:24 -0700 | [diff] [blame] | 405 | if (in_compat_syscall()) { |
Dmitry Torokhov | befde02 | 2013-02-18 11:26:11 +0100 | [diff] [blame] | 406 | u32 type; |
| 407 | |
| 408 | if (get_user(type, buffer)) |
| 409 | return -EFAULT; |
| 410 | |
| 411 | if (type == UHID_CREATE) { |
| 412 | /* |
| 413 | * This is our messed up request with compat pointer. |
| 414 | * It is largish (more than 256 bytes) so we better |
| 415 | * allocate it from the heap. |
| 416 | */ |
| 417 | struct uhid_create_req_compat *compat; |
| 418 | |
David Herrmann | 80897aa | 2013-11-26 13:58:18 +0100 | [diff] [blame] | 419 | compat = kzalloc(sizeof(*compat), GFP_KERNEL); |
Dmitry Torokhov | befde02 | 2013-02-18 11:26:11 +0100 | [diff] [blame] | 420 | if (!compat) |
| 421 | return -ENOMEM; |
| 422 | |
| 423 | buffer += sizeof(type); |
| 424 | len -= sizeof(type); |
| 425 | if (copy_from_user(compat, buffer, |
| 426 | min(len, sizeof(*compat)))) { |
| 427 | kfree(compat); |
| 428 | return -EFAULT; |
| 429 | } |
| 430 | |
| 431 | /* Shuffle the data over to proper structure */ |
| 432 | event->type = type; |
| 433 | |
| 434 | memcpy(event->u.create.name, compat->name, |
| 435 | sizeof(compat->name)); |
| 436 | memcpy(event->u.create.phys, compat->phys, |
| 437 | sizeof(compat->phys)); |
| 438 | memcpy(event->u.create.uniq, compat->uniq, |
| 439 | sizeof(compat->uniq)); |
| 440 | |
| 441 | event->u.create.rd_data = compat_ptr(compat->rd_data); |
| 442 | event->u.create.rd_size = compat->rd_size; |
| 443 | |
| 444 | event->u.create.bus = compat->bus; |
| 445 | event->u.create.vendor = compat->vendor; |
| 446 | event->u.create.product = compat->product; |
| 447 | event->u.create.version = compat->version; |
| 448 | event->u.create.country = compat->country; |
| 449 | |
| 450 | kfree(compat); |
| 451 | return 0; |
| 452 | } |
| 453 | /* All others can be copied directly */ |
| 454 | } |
| 455 | |
| 456 | if (copy_from_user(event, buffer, min(len, sizeof(*event)))) |
| 457 | return -EFAULT; |
| 458 | |
| 459 | return 0; |
| 460 | } |
| 461 | #else |
| 462 | static int uhid_event_from_user(const char __user *buffer, size_t len, |
| 463 | struct uhid_event *event) |
| 464 | { |
| 465 | if (copy_from_user(event, buffer, min(len, sizeof(*event)))) |
| 466 | return -EFAULT; |
| 467 | |
| 468 | return 0; |
| 469 | } |
| 470 | #endif |
| 471 | |
Petri Gynther | 4522643 | 2014-03-24 13:50:01 -0700 | [diff] [blame] | 472 | static int uhid_dev_create2(struct uhid_device *uhid, |
| 473 | const struct uhid_event *ev) |
| 474 | { |
| 475 | struct hid_device *hid; |
David Herrmann | 25be7fe | 2014-07-29 17:14:18 +0200 | [diff] [blame] | 476 | size_t rd_size, len; |
David Herrmann | 41c4a46 | 2014-07-29 17:14:17 +0200 | [diff] [blame] | 477 | void *rd_data; |
Petri Gynther | 4522643 | 2014-03-24 13:50:01 -0700 | [diff] [blame] | 478 | int ret; |
| 479 | |
| 480 | if (uhid->running) |
| 481 | return -EALREADY; |
| 482 | |
David Herrmann | 41c4a46 | 2014-07-29 17:14:17 +0200 | [diff] [blame] | 483 | rd_size = ev->u.create2.rd_size; |
| 484 | if (rd_size <= 0 || rd_size > HID_MAX_DESCRIPTOR_SIZE) |
Petri Gynther | 4522643 | 2014-03-24 13:50:01 -0700 | [diff] [blame] | 485 | return -EINVAL; |
| 486 | |
David Herrmann | 41c4a46 | 2014-07-29 17:14:17 +0200 | [diff] [blame] | 487 | rd_data = kmemdup(ev->u.create2.rd_data, rd_size, GFP_KERNEL); |
| 488 | if (!rd_data) |
Petri Gynther | 4522643 | 2014-03-24 13:50:01 -0700 | [diff] [blame] | 489 | return -ENOMEM; |
| 490 | |
David Herrmann | 41c4a46 | 2014-07-29 17:14:17 +0200 | [diff] [blame] | 491 | uhid->rd_size = rd_size; |
| 492 | uhid->rd_data = rd_data; |
| 493 | |
Petri Gynther | 4522643 | 2014-03-24 13:50:01 -0700 | [diff] [blame] | 494 | hid = hid_allocate_device(); |
| 495 | if (IS_ERR(hid)) { |
| 496 | ret = PTR_ERR(hid); |
| 497 | goto err_free; |
| 498 | } |
| 499 | |
David Herrmann | 699faa9 | 2018-11-14 14:16:42 +0100 | [diff] [blame] | 500 | /* @hid is zero-initialized, strncpy() is correct, strlcpy() not */ |
| 501 | len = min(sizeof(hid->name), sizeof(ev->u.create2.name)) - 1; |
| 502 | strncpy(hid->name, ev->u.create2.name, len); |
| 503 | len = min(sizeof(hid->phys), sizeof(ev->u.create2.phys)) - 1; |
| 504 | strncpy(hid->phys, ev->u.create2.phys, len); |
| 505 | len = min(sizeof(hid->uniq), sizeof(ev->u.create2.uniq)) - 1; |
| 506 | strncpy(hid->uniq, ev->u.create2.uniq, len); |
Petri Gynther | 4522643 | 2014-03-24 13:50:01 -0700 | [diff] [blame] | 507 | |
| 508 | hid->ll_driver = &uhid_hid_driver; |
| 509 | hid->bus = ev->u.create2.bus; |
| 510 | hid->vendor = ev->u.create2.vendor; |
| 511 | hid->product = ev->u.create2.product; |
| 512 | hid->version = ev->u.create2.version; |
| 513 | hid->country = ev->u.create2.country; |
| 514 | hid->driver_data = uhid; |
| 515 | hid->dev.parent = uhid_misc.this_device; |
| 516 | |
| 517 | uhid->hid = hid; |
| 518 | uhid->running = true; |
| 519 | |
Roderick Colenbrander | 67f8ecc | 2016-05-18 13:11:09 -0700 | [diff] [blame] | 520 | /* Adding of a HID device is done through a worker, to allow HID drivers |
| 521 | * which use feature requests during .probe to work, without they would |
| 522 | * be blocked on devlock, which is held by uhid_char_write. |
| 523 | */ |
| 524 | schedule_work(&uhid->worker); |
Petri Gynther | 4522643 | 2014-03-24 13:50:01 -0700 | [diff] [blame] | 525 | |
| 526 | return 0; |
| 527 | |
Petri Gynther | 4522643 | 2014-03-24 13:50:01 -0700 | [diff] [blame] | 528 | err_free: |
| 529 | kfree(uhid->rd_data); |
David Herrmann | 41c4a46 | 2014-07-29 17:14:17 +0200 | [diff] [blame] | 530 | uhid->rd_data = NULL; |
| 531 | uhid->rd_size = 0; |
Petri Gynther | 4522643 | 2014-03-24 13:50:01 -0700 | [diff] [blame] | 532 | return ret; |
| 533 | } |
| 534 | |
David Herrmann | 56c4775 | 2014-07-29 17:14:16 +0200 | [diff] [blame] | 535 | static int uhid_dev_create(struct uhid_device *uhid, |
| 536 | struct uhid_event *ev) |
| 537 | { |
| 538 | struct uhid_create_req orig; |
| 539 | |
| 540 | orig = ev->u.create; |
| 541 | |
| 542 | if (orig.rd_size <= 0 || orig.rd_size > HID_MAX_DESCRIPTOR_SIZE) |
| 543 | return -EINVAL; |
| 544 | if (copy_from_user(&ev->u.create2.rd_data, orig.rd_data, orig.rd_size)) |
| 545 | return -EFAULT; |
| 546 | |
| 547 | memcpy(ev->u.create2.name, orig.name, sizeof(orig.name)); |
| 548 | memcpy(ev->u.create2.phys, orig.phys, sizeof(orig.phys)); |
| 549 | memcpy(ev->u.create2.uniq, orig.uniq, sizeof(orig.uniq)); |
| 550 | ev->u.create2.rd_size = orig.rd_size; |
| 551 | ev->u.create2.bus = orig.bus; |
| 552 | ev->u.create2.vendor = orig.vendor; |
| 553 | ev->u.create2.product = orig.product; |
| 554 | ev->u.create2.version = orig.version; |
| 555 | ev->u.create2.country = orig.country; |
| 556 | |
| 557 | return uhid_dev_create2(uhid, ev); |
| 558 | } |
| 559 | |
David Herrmann | d365c6c | 2012-06-10 15:16:18 +0200 | [diff] [blame] | 560 | static int uhid_dev_destroy(struct uhid_device *uhid) |
| 561 | { |
| 562 | if (!uhid->running) |
| 563 | return -EINVAL; |
| 564 | |
| 565 | uhid->running = false; |
David Herrmann | fcfcf0d | 2012-06-10 15:16:25 +0200 | [diff] [blame] | 566 | wake_up_interruptible(&uhid->report_wait); |
David Herrmann | d365c6c | 2012-06-10 15:16:18 +0200 | [diff] [blame] | 567 | |
Roderick Colenbrander | 67f8ecc | 2016-05-18 13:11:09 -0700 | [diff] [blame] | 568 | cancel_work_sync(&uhid->worker); |
| 569 | |
David Herrmann | d365c6c | 2012-06-10 15:16:18 +0200 | [diff] [blame] | 570 | hid_destroy_device(uhid->hid); |
| 571 | kfree(uhid->rd_data); |
| 572 | |
| 573 | return 0; |
| 574 | } |
| 575 | |
David Herrmann | 5e87a36 | 2012-06-10 15:16:19 +0200 | [diff] [blame] | 576 | static int uhid_dev_input(struct uhid_device *uhid, struct uhid_event *ev) |
| 577 | { |
| 578 | if (!uhid->running) |
| 579 | return -EINVAL; |
| 580 | |
| 581 | hid_input_report(uhid->hid, HID_INPUT_REPORT, ev->u.input.data, |
| 582 | min_t(size_t, ev->u.input.size, UHID_DATA_MAX), 0); |
| 583 | |
| 584 | return 0; |
| 585 | } |
| 586 | |
Petri Gynther | 4522643 | 2014-03-24 13:50:01 -0700 | [diff] [blame] | 587 | static int uhid_dev_input2(struct uhid_device *uhid, struct uhid_event *ev) |
| 588 | { |
| 589 | if (!uhid->running) |
| 590 | return -EINVAL; |
| 591 | |
| 592 | hid_input_report(uhid->hid, HID_INPUT_REPORT, ev->u.input2.data, |
| 593 | min_t(size_t, ev->u.input2.size, UHID_DATA_MAX), 0); |
| 594 | |
| 595 | return 0; |
| 596 | } |
| 597 | |
David Herrmann | fa71f32 | 2014-07-29 17:14:21 +0200 | [diff] [blame] | 598 | static int uhid_dev_get_report_reply(struct uhid_device *uhid, |
| 599 | struct uhid_event *ev) |
David Herrmann | fcfcf0d | 2012-06-10 15:16:25 +0200 | [diff] [blame] | 600 | { |
David Herrmann | fcfcf0d | 2012-06-10 15:16:25 +0200 | [diff] [blame] | 601 | if (!uhid->running) |
| 602 | return -EINVAL; |
| 603 | |
David Herrmann | 11c2215 | 2014-07-29 17:14:24 +0200 | [diff] [blame] | 604 | uhid_report_wake_up(uhid, ev->u.get_report_reply.id, ev); |
| 605 | return 0; |
| 606 | } |
David Herrmann | fcfcf0d | 2012-06-10 15:16:25 +0200 | [diff] [blame] | 607 | |
David Herrmann | 11c2215 | 2014-07-29 17:14:24 +0200 | [diff] [blame] | 608 | static int uhid_dev_set_report_reply(struct uhid_device *uhid, |
| 609 | struct uhid_event *ev) |
| 610 | { |
| 611 | if (!uhid->running) |
| 612 | return -EINVAL; |
David Herrmann | fcfcf0d | 2012-06-10 15:16:25 +0200 | [diff] [blame] | 613 | |
David Herrmann | 11c2215 | 2014-07-29 17:14:24 +0200 | [diff] [blame] | 614 | uhid_report_wake_up(uhid, ev->u.set_report_reply.id, ev); |
David Herrmann | fcfcf0d | 2012-06-10 15:16:25 +0200 | [diff] [blame] | 615 | return 0; |
| 616 | } |
| 617 | |
David Herrmann | 1ccd7a2 | 2012-06-10 15:16:13 +0200 | [diff] [blame] | 618 | static int uhid_char_open(struct inode *inode, struct file *file) |
| 619 | { |
David Herrmann | ace3d86 | 2012-06-10 15:16:14 +0200 | [diff] [blame] | 620 | struct uhid_device *uhid; |
| 621 | |
| 622 | uhid = kzalloc(sizeof(*uhid), GFP_KERNEL); |
| 623 | if (!uhid) |
| 624 | return -ENOMEM; |
| 625 | |
David Herrmann | d937ae5 | 2012-06-10 15:16:16 +0200 | [diff] [blame] | 626 | mutex_init(&uhid->devlock); |
David Herrmann | fcfcf0d | 2012-06-10 15:16:25 +0200 | [diff] [blame] | 627 | mutex_init(&uhid->report_lock); |
David Herrmann | ace3d86 | 2012-06-10 15:16:14 +0200 | [diff] [blame] | 628 | spin_lock_init(&uhid->qlock); |
| 629 | init_waitqueue_head(&uhid->waitq); |
David Herrmann | fcfcf0d | 2012-06-10 15:16:25 +0200 | [diff] [blame] | 630 | init_waitqueue_head(&uhid->report_wait); |
David Herrmann | d365c6c | 2012-06-10 15:16:18 +0200 | [diff] [blame] | 631 | uhid->running = false; |
Roderick Colenbrander | 67f8ecc | 2016-05-18 13:11:09 -0700 | [diff] [blame] | 632 | INIT_WORK(&uhid->worker, uhid_device_add_worker); |
David Herrmann | ace3d86 | 2012-06-10 15:16:14 +0200 | [diff] [blame] | 633 | |
| 634 | file->private_data = uhid; |
| 635 | nonseekable_open(inode, file); |
| 636 | |
David Herrmann | 1ccd7a2 | 2012-06-10 15:16:13 +0200 | [diff] [blame] | 637 | return 0; |
| 638 | } |
| 639 | |
| 640 | static int uhid_char_release(struct inode *inode, struct file *file) |
| 641 | { |
David Herrmann | ace3d86 | 2012-06-10 15:16:14 +0200 | [diff] [blame] | 642 | struct uhid_device *uhid = file->private_data; |
| 643 | unsigned int i; |
| 644 | |
David Herrmann | d365c6c | 2012-06-10 15:16:18 +0200 | [diff] [blame] | 645 | uhid_dev_destroy(uhid); |
| 646 | |
David Herrmann | ace3d86 | 2012-06-10 15:16:14 +0200 | [diff] [blame] | 647 | for (i = 0; i < UHID_BUFSIZE; ++i) |
| 648 | kfree(uhid->outq[i]); |
| 649 | |
| 650 | kfree(uhid); |
| 651 | |
David Herrmann | 1ccd7a2 | 2012-06-10 15:16:13 +0200 | [diff] [blame] | 652 | return 0; |
| 653 | } |
| 654 | |
| 655 | static ssize_t uhid_char_read(struct file *file, char __user *buffer, |
| 656 | size_t count, loff_t *ppos) |
| 657 | { |
David Herrmann | d937ae5 | 2012-06-10 15:16:16 +0200 | [diff] [blame] | 658 | struct uhid_device *uhid = file->private_data; |
| 659 | int ret; |
| 660 | unsigned long flags; |
| 661 | size_t len; |
| 662 | |
| 663 | /* they need at least the "type" member of uhid_event */ |
| 664 | if (count < sizeof(__u32)) |
| 665 | return -EINVAL; |
| 666 | |
| 667 | try_again: |
| 668 | if (file->f_flags & O_NONBLOCK) { |
| 669 | if (uhid->head == uhid->tail) |
| 670 | return -EAGAIN; |
| 671 | } else { |
| 672 | ret = wait_event_interruptible(uhid->waitq, |
| 673 | uhid->head != uhid->tail); |
| 674 | if (ret) |
| 675 | return ret; |
| 676 | } |
| 677 | |
| 678 | ret = mutex_lock_interruptible(&uhid->devlock); |
| 679 | if (ret) |
| 680 | return ret; |
| 681 | |
| 682 | if (uhid->head == uhid->tail) { |
| 683 | mutex_unlock(&uhid->devlock); |
| 684 | goto try_again; |
| 685 | } else { |
| 686 | len = min(count, sizeof(**uhid->outq)); |
Vinicius Costa Gomes | adefb69 | 2012-07-14 18:59:25 -0300 | [diff] [blame] | 687 | if (copy_to_user(buffer, uhid->outq[uhid->tail], len)) { |
David Herrmann | d937ae5 | 2012-06-10 15:16:16 +0200 | [diff] [blame] | 688 | ret = -EFAULT; |
| 689 | } else { |
| 690 | kfree(uhid->outq[uhid->tail]); |
| 691 | uhid->outq[uhid->tail] = NULL; |
| 692 | |
| 693 | spin_lock_irqsave(&uhid->qlock, flags); |
| 694 | uhid->tail = (uhid->tail + 1) % UHID_BUFSIZE; |
| 695 | spin_unlock_irqrestore(&uhid->qlock, flags); |
| 696 | } |
| 697 | } |
| 698 | |
| 699 | mutex_unlock(&uhid->devlock); |
| 700 | return ret ? ret : len; |
David Herrmann | 1ccd7a2 | 2012-06-10 15:16:13 +0200 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | static ssize_t uhid_char_write(struct file *file, const char __user *buffer, |
| 704 | size_t count, loff_t *ppos) |
| 705 | { |
David Herrmann | 6664ef7 | 2012-06-10 15:16:17 +0200 | [diff] [blame] | 706 | struct uhid_device *uhid = file->private_data; |
| 707 | int ret; |
| 708 | size_t len; |
| 709 | |
| 710 | /* we need at least the "type" member of uhid_event */ |
| 711 | if (count < sizeof(__u32)) |
| 712 | return -EINVAL; |
| 713 | |
| 714 | ret = mutex_lock_interruptible(&uhid->devlock); |
| 715 | if (ret) |
| 716 | return ret; |
| 717 | |
| 718 | memset(&uhid->input_buf, 0, sizeof(uhid->input_buf)); |
| 719 | len = min(count, sizeof(uhid->input_buf)); |
Dmitry Torokhov | befde02 | 2013-02-18 11:26:11 +0100 | [diff] [blame] | 720 | |
| 721 | ret = uhid_event_from_user(buffer, len, &uhid->input_buf); |
| 722 | if (ret) |
David Herrmann | 6664ef7 | 2012-06-10 15:16:17 +0200 | [diff] [blame] | 723 | goto unlock; |
David Herrmann | 6664ef7 | 2012-06-10 15:16:17 +0200 | [diff] [blame] | 724 | |
| 725 | switch (uhid->input_buf.type) { |
David Herrmann | d365c6c | 2012-06-10 15:16:18 +0200 | [diff] [blame] | 726 | case UHID_CREATE: |
Eric Biggers | cf7de65 | 2018-11-14 13:55:09 -0800 | [diff] [blame] | 727 | /* |
| 728 | * 'struct uhid_create_req' contains a __user pointer which is |
| 729 | * copied from, so it's unsafe to allow this with elevated |
| 730 | * privileges (e.g. from a setuid binary) or via kernel_write(). |
| 731 | */ |
| 732 | if (file->f_cred != current_cred() || uaccess_kernel()) { |
| 733 | pr_err_once("UHID_CREATE from different security context by process %d (%s), this is not allowed.\n", |
| 734 | task_tgid_vnr(current), current->comm); |
| 735 | ret = -EACCES; |
| 736 | goto unlock; |
| 737 | } |
David Herrmann | d365c6c | 2012-06-10 15:16:18 +0200 | [diff] [blame] | 738 | ret = uhid_dev_create(uhid, &uhid->input_buf); |
| 739 | break; |
Petri Gynther | 4522643 | 2014-03-24 13:50:01 -0700 | [diff] [blame] | 740 | case UHID_CREATE2: |
| 741 | ret = uhid_dev_create2(uhid, &uhid->input_buf); |
| 742 | break; |
David Herrmann | d365c6c | 2012-06-10 15:16:18 +0200 | [diff] [blame] | 743 | case UHID_DESTROY: |
| 744 | ret = uhid_dev_destroy(uhid); |
| 745 | break; |
David Herrmann | 5e87a36 | 2012-06-10 15:16:19 +0200 | [diff] [blame] | 746 | case UHID_INPUT: |
| 747 | ret = uhid_dev_input(uhid, &uhid->input_buf); |
| 748 | break; |
Petri Gynther | 4522643 | 2014-03-24 13:50:01 -0700 | [diff] [blame] | 749 | case UHID_INPUT2: |
| 750 | ret = uhid_dev_input2(uhid, &uhid->input_buf); |
| 751 | break; |
David Herrmann | fa71f32 | 2014-07-29 17:14:21 +0200 | [diff] [blame] | 752 | case UHID_GET_REPORT_REPLY: |
| 753 | ret = uhid_dev_get_report_reply(uhid, &uhid->input_buf); |
David Herrmann | fcfcf0d | 2012-06-10 15:16:25 +0200 | [diff] [blame] | 754 | break; |
David Herrmann | 11c2215 | 2014-07-29 17:14:24 +0200 | [diff] [blame] | 755 | case UHID_SET_REPORT_REPLY: |
| 756 | ret = uhid_dev_set_report_reply(uhid, &uhid->input_buf); |
| 757 | break; |
David Herrmann | 6664ef7 | 2012-06-10 15:16:17 +0200 | [diff] [blame] | 758 | default: |
| 759 | ret = -EOPNOTSUPP; |
| 760 | } |
| 761 | |
| 762 | unlock: |
| 763 | mutex_unlock(&uhid->devlock); |
| 764 | |
| 765 | /* return "count" not "len" to not confuse the caller */ |
| 766 | return ret ? ret : count; |
David Herrmann | 1ccd7a2 | 2012-06-10 15:16:13 +0200 | [diff] [blame] | 767 | } |
| 768 | |
Al Viro | afc9a42 | 2017-07-03 06:39:46 -0400 | [diff] [blame] | 769 | static __poll_t uhid_char_poll(struct file *file, poll_table *wait) |
David Herrmann | 1ccd7a2 | 2012-06-10 15:16:13 +0200 | [diff] [blame] | 770 | { |
David Herrmann | 1f9dec1 | 2012-06-10 15:16:15 +0200 | [diff] [blame] | 771 | struct uhid_device *uhid = file->private_data; |
| 772 | |
| 773 | poll_wait(file, &uhid->waitq, wait); |
| 774 | |
| 775 | if (uhid->head != uhid->tail) |
Linus Torvalds | a9a0884 | 2018-02-11 14:34:03 -0800 | [diff] [blame] | 776 | return EPOLLIN | EPOLLRDNORM; |
David Herrmann | 1f9dec1 | 2012-06-10 15:16:15 +0200 | [diff] [blame] | 777 | |
David Herrmann | 1ccd7a2 | 2012-06-10 15:16:13 +0200 | [diff] [blame] | 778 | return 0; |
| 779 | } |
| 780 | |
| 781 | static const struct file_operations uhid_fops = { |
| 782 | .owner = THIS_MODULE, |
| 783 | .open = uhid_char_open, |
| 784 | .release = uhid_char_release, |
| 785 | .read = uhid_char_read, |
| 786 | .write = uhid_char_write, |
| 787 | .poll = uhid_char_poll, |
| 788 | .llseek = no_llseek, |
| 789 | }; |
| 790 | |
| 791 | static struct miscdevice uhid_misc = { |
| 792 | .fops = &uhid_fops, |
David Herrmann | 19872d2 | 2013-09-09 18:33:54 +0200 | [diff] [blame] | 793 | .minor = UHID_MINOR, |
David Herrmann | 1ccd7a2 | 2012-06-10 15:16:13 +0200 | [diff] [blame] | 794 | .name = UHID_NAME, |
| 795 | }; |
PrasannaKumar Muralidharan | ca75d60 | 2016-08-25 22:30:49 +0530 | [diff] [blame] | 796 | module_misc_device(uhid_misc); |
David Herrmann | 1ccd7a2 | 2012-06-10 15:16:13 +0200 | [diff] [blame] | 797 | |
David Herrmann | 1ccd7a2 | 2012-06-10 15:16:13 +0200 | [diff] [blame] | 798 | MODULE_LICENSE("GPL"); |
| 799 | MODULE_AUTHOR("David Herrmann <dh.herrmann@gmail.com>"); |
| 800 | MODULE_DESCRIPTION("User-space I/O driver support for HID subsystem"); |
David Herrmann | 19872d2 | 2013-09-09 18:33:54 +0200 | [diff] [blame] | 801 | MODULE_ALIAS_MISCDEV(UHID_MINOR); |
Marcel Holtmann | 60cbd53 | 2013-09-01 11:02:46 -0700 | [diff] [blame] | 802 | MODULE_ALIAS("devname:" UHID_NAME); |