1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (c) 2001 Paul Stewart
4 * Copyright (c) 2001 Vojtech Pavlik
6 * HID char devices, giving access to raw HID device events.
11 * Should you need to contact me, the author, you can do so either by
12 * e-mail - mail your message to Paul Stewart <stewart@wetlogic.net>
15 #include <linux/poll.h>
16 #include <linux/slab.h>
17 #include <linux/sched/signal.h>
18 #include <linux/module.h>
19 #include <linux/init.h>
20 #include <linux/input.h>
21 #include <linux/usb.h>
22 #include <linux/hid.h>
23 #include <linux/hiddev.h>
24 #include <linux/compat.h>
25 #include <linux/vmalloc.h>
26 #include <linux/nospec.h>
29 #ifdef CONFIG_USB_DYNAMIC_MINORS
30 #define HIDDEV_MINOR_BASE 0
31 #define HIDDEV_MINORS 256
33 #define HIDDEV_MINOR_BASE 96
34 #define HIDDEV_MINORS 16
36 #define HIDDEV_BUFFER_SIZE 2048
39 struct hiddev_usage_ref buffer
[HIDDEV_BUFFER_SIZE
];
43 struct fasync_struct
*fasync
;
44 struct hiddev
*hiddev
;
45 struct list_head node
;
46 struct mutex thread_lock
;
50 * Find a report, given the report's type and ID. The ID can be specified
51 * indirectly by REPORT_ID_FIRST (which returns the first report of the given
52 * type) or by (REPORT_ID_NEXT | old_id), which returns the next report of the
53 * given type which follows old_id.
55 static struct hid_report
*
56 hiddev_lookup_report(struct hid_device
*hid
, struct hiddev_report_info
*rinfo
)
58 unsigned int flags
= rinfo
->report_id
& ~HID_REPORT_ID_MASK
;
59 unsigned int rid
= rinfo
->report_id
& HID_REPORT_ID_MASK
;
60 struct hid_report_enum
*report_enum
;
61 struct hid_report
*report
;
62 struct list_head
*list
;
64 if (rinfo
->report_type
< HID_REPORT_TYPE_MIN
||
65 rinfo
->report_type
> HID_REPORT_TYPE_MAX
)
68 report_enum
= hid
->report_enum
+
69 (rinfo
->report_type
- HID_REPORT_TYPE_MIN
);
72 case 0: /* Nothing to do -- report_id is already set correctly */
75 case HID_REPORT_ID_FIRST
:
76 if (list_empty(&report_enum
->report_list
))
79 list
= report_enum
->report_list
.next
;
80 report
= list_entry(list
, struct hid_report
, list
);
81 rinfo
->report_id
= report
->id
;
84 case HID_REPORT_ID_NEXT
:
85 report
= report_enum
->report_id_hash
[rid
];
89 list
= report
->list
.next
;
90 if (list
== &report_enum
->report_list
)
93 report
= list_entry(list
, struct hid_report
, list
);
94 rinfo
->report_id
= report
->id
;
101 return report_enum
->report_id_hash
[rinfo
->report_id
];
105 * Perform an exhaustive search of the report table for a usage, given its
108 static struct hid_field
*
109 hiddev_lookup_usage(struct hid_device
*hid
, struct hiddev_usage_ref
*uref
)
112 struct hid_report
*report
;
113 struct hid_report_enum
*report_enum
;
114 struct hid_field
*field
;
116 if (uref
->report_type
< HID_REPORT_TYPE_MIN
||
117 uref
->report_type
> HID_REPORT_TYPE_MAX
)
120 report_enum
= hid
->report_enum
+
121 (uref
->report_type
- HID_REPORT_TYPE_MIN
);
123 list_for_each_entry(report
, &report_enum
->report_list
, list
) {
124 for (i
= 0; i
< report
->maxfield
; i
++) {
125 field
= report
->field
[i
];
126 for (j
= 0; j
< field
->maxusage
; j
++) {
127 if (field
->usage
[j
].hid
== uref
->usage_code
) {
128 uref
->report_id
= report
->id
;
129 uref
->field_index
= i
;
130 uref
->usage_index
= j
;
140 static void hiddev_send_event(struct hid_device
*hid
,
141 struct hiddev_usage_ref
*uref
)
143 struct hiddev
*hiddev
= hid
->hiddev
;
144 struct hiddev_list
*list
;
147 spin_lock_irqsave(&hiddev
->list_lock
, flags
);
148 list_for_each_entry(list
, &hiddev
->list
, node
) {
149 if (uref
->field_index
!= HID_FIELD_INDEX_NONE
||
150 (list
->flags
& HIDDEV_FLAG_REPORT
) != 0) {
151 list
->buffer
[list
->head
] = *uref
;
152 list
->head
= (list
->head
+ 1) &
153 (HIDDEV_BUFFER_SIZE
- 1);
154 kill_fasync(&list
->fasync
, SIGIO
, POLL_IN
);
157 spin_unlock_irqrestore(&hiddev
->list_lock
, flags
);
159 wake_up_interruptible(&hiddev
->wait
);
163 * This is where hid.c calls into hiddev to pass an event that occurred over
166 void hiddev_hid_event(struct hid_device
*hid
, struct hid_field
*field
,
167 struct hid_usage
*usage
, __s32 value
)
169 unsigned type
= field
->report_type
;
170 struct hiddev_usage_ref uref
;
173 (type
== HID_INPUT_REPORT
) ? HID_REPORT_TYPE_INPUT
:
174 ((type
== HID_OUTPUT_REPORT
) ? HID_REPORT_TYPE_OUTPUT
:
175 ((type
== HID_FEATURE_REPORT
) ? HID_REPORT_TYPE_FEATURE
: 0));
176 uref
.report_id
= field
->report
->id
;
177 uref
.field_index
= field
->index
;
178 uref
.usage_index
= (usage
- field
->usage
);
179 uref
.usage_code
= usage
->hid
;
182 hiddev_send_event(hid
, &uref
);
184 EXPORT_SYMBOL_GPL(hiddev_hid_event
);
186 void hiddev_report_event(struct hid_device
*hid
, struct hid_report
*report
)
188 unsigned type
= report
->type
;
189 struct hiddev_usage_ref uref
;
191 memset(&uref
, 0, sizeof(uref
));
193 (type
== HID_INPUT_REPORT
) ? HID_REPORT_TYPE_INPUT
:
194 ((type
== HID_OUTPUT_REPORT
) ? HID_REPORT_TYPE_OUTPUT
:
195 ((type
== HID_FEATURE_REPORT
) ? HID_REPORT_TYPE_FEATURE
: 0));
196 uref
.report_id
= report
->id
;
197 uref
.field_index
= HID_FIELD_INDEX_NONE
;
199 hiddev_send_event(hid
, &uref
);
205 static int hiddev_fasync(int fd
, struct file
*file
, int on
)
207 struct hiddev_list
*list
= file
->private_data
;
209 return fasync_helper(fd
, file
, on
, &list
->fasync
);
216 static int hiddev_release(struct inode
* inode
, struct file
* file
)
218 struct hiddev_list
*list
= file
->private_data
;
221 spin_lock_irqsave(&list
->hiddev
->list_lock
, flags
);
222 list_del(&list
->node
);
223 spin_unlock_irqrestore(&list
->hiddev
->list_lock
, flags
);
225 mutex_lock(&list
->hiddev
->existancelock
);
226 if (!--list
->hiddev
->open
) {
227 if (list
->hiddev
->exist
) {
228 hid_hw_close(list
->hiddev
->hid
);
229 hid_hw_power(list
->hiddev
->hid
, PM_HINT_NORMAL
);
231 mutex_unlock(&list
->hiddev
->existancelock
);
238 mutex_unlock(&list
->hiddev
->existancelock
);
244 static int __hiddev_open(struct hiddev
*hiddev
, struct file
*file
)
246 struct hiddev_list
*list
;
249 lockdep_assert_held(&hiddev
->existancelock
);
251 list
= vzalloc(sizeof(*list
));
255 mutex_init(&list
->thread_lock
);
256 list
->hiddev
= hiddev
;
258 if (!hiddev
->open
++) {
259 error
= hid_hw_power(hiddev
->hid
, PM_HINT_FULLON
);
263 error
= hid_hw_open(hiddev
->hid
);
265 goto err_normal_power
;
268 spin_lock_irq(&hiddev
->list_lock
);
269 list_add_tail(&list
->node
, &hiddev
->list
);
270 spin_unlock_irq(&hiddev
->list_lock
);
272 file
->private_data
= list
;
277 hid_hw_power(hiddev
->hid
, PM_HINT_NORMAL
);
287 static int hiddev_open(struct inode
*inode
, struct file
*file
)
289 struct usb_interface
*intf
;
290 struct hid_device
*hid
;
291 struct hiddev
*hiddev
;
294 intf
= usbhid_find_interface(iminor(inode
));
298 hid
= usb_get_intfdata(intf
);
299 hiddev
= hid
->hiddev
;
301 mutex_lock(&hiddev
->existancelock
);
302 res
= hiddev
->exist
? __hiddev_open(hiddev
, file
) : -ENODEV
;
303 mutex_unlock(&hiddev
->existancelock
);
311 static ssize_t
hiddev_write(struct file
* file
, const char __user
* buffer
, size_t count
, loff_t
*ppos
)
319 static ssize_t
hiddev_read(struct file
* file
, char __user
* buffer
, size_t count
, loff_t
*ppos
)
322 struct hiddev_list
*list
= file
->private_data
;
326 event_size
= ((list
->flags
& HIDDEV_FLAG_UREF
) != 0) ?
327 sizeof(struct hiddev_usage_ref
) : sizeof(struct hiddev_event
);
329 if (count
< event_size
)
332 /* lock against other threads */
333 retval
= mutex_lock_interruptible(&list
->thread_lock
);
337 while (retval
== 0) {
338 if (list
->head
== list
->tail
) {
339 prepare_to_wait(&list
->hiddev
->wait
, &wait
, TASK_INTERRUPTIBLE
);
341 while (list
->head
== list
->tail
) {
342 if (signal_pending(current
)) {
343 retval
= -ERESTARTSYS
;
346 if (!list
->hiddev
->exist
) {
350 if (file
->f_flags
& O_NONBLOCK
) {
355 /* let O_NONBLOCK tasks run */
356 mutex_unlock(&list
->thread_lock
);
358 if (mutex_lock_interruptible(&list
->thread_lock
)) {
359 finish_wait(&list
->hiddev
->wait
, &wait
);
362 set_current_state(TASK_INTERRUPTIBLE
);
364 finish_wait(&list
->hiddev
->wait
, &wait
);
369 mutex_unlock(&list
->thread_lock
);
374 while (list
->head
!= list
->tail
&&
375 retval
+ event_size
<= count
) {
376 if ((list
->flags
& HIDDEV_FLAG_UREF
) == 0) {
377 if (list
->buffer
[list
->tail
].field_index
!= HID_FIELD_INDEX_NONE
) {
378 struct hiddev_event event
;
380 event
.hid
= list
->buffer
[list
->tail
].usage_code
;
381 event
.value
= list
->buffer
[list
->tail
].value
;
382 if (copy_to_user(buffer
+ retval
, &event
, sizeof(struct hiddev_event
))) {
383 mutex_unlock(&list
->thread_lock
);
386 retval
+= sizeof(struct hiddev_event
);
389 if (list
->buffer
[list
->tail
].field_index
!= HID_FIELD_INDEX_NONE
||
390 (list
->flags
& HIDDEV_FLAG_REPORT
) != 0) {
392 if (copy_to_user(buffer
+ retval
, list
->buffer
+ list
->tail
, sizeof(struct hiddev_usage_ref
))) {
393 mutex_unlock(&list
->thread_lock
);
396 retval
+= sizeof(struct hiddev_usage_ref
);
399 list
->tail
= (list
->tail
+ 1) & (HIDDEV_BUFFER_SIZE
- 1);
403 mutex_unlock(&list
->thread_lock
);
410 * No kernel lock - fine
412 static __poll_t
hiddev_poll(struct file
*file
, poll_table
*wait
)
414 struct hiddev_list
*list
= file
->private_data
;
416 poll_wait(file
, &list
->hiddev
->wait
, wait
);
417 if (list
->head
!= list
->tail
)
418 return EPOLLIN
| EPOLLRDNORM
| EPOLLOUT
;
419 if (!list
->hiddev
->exist
)
420 return EPOLLERR
| EPOLLHUP
;
427 static noinline
int hiddev_ioctl_usage(struct hiddev
*hiddev
, unsigned int cmd
, void __user
*user_arg
)
429 struct hid_device
*hid
= hiddev
->hid
;
430 struct hiddev_report_info rinfo
;
431 struct hiddev_usage_ref_multi
*uref_multi
= NULL
;
432 struct hiddev_usage_ref
*uref
;
433 struct hid_report
*report
;
434 struct hid_field
*field
;
437 uref_multi
= kmalloc(sizeof(struct hiddev_usage_ref_multi
), GFP_KERNEL
);
440 uref
= &uref_multi
->uref
;
441 if (cmd
== HIDIOCGUSAGES
|| cmd
== HIDIOCSUSAGES
) {
442 if (copy_from_user(uref_multi
, user_arg
,
443 sizeof(*uref_multi
)))
446 if (copy_from_user(uref
, user_arg
, sizeof(*uref
)))
452 rinfo
.report_type
= uref
->report_type
;
453 rinfo
.report_id
= uref
->report_id
;
454 if ((report
= hiddev_lookup_report(hid
, &rinfo
)) == NULL
)
457 if (uref
->field_index
>= report
->maxfield
)
459 uref
->field_index
= array_index_nospec(uref
->field_index
,
462 field
= report
->field
[uref
->field_index
];
463 if (uref
->usage_index
>= field
->maxusage
)
465 uref
->usage_index
= array_index_nospec(uref
->usage_index
,
468 uref
->usage_code
= field
->usage
[uref
->usage_index
].hid
;
470 if (copy_to_user(user_arg
, uref
, sizeof(*uref
)))
476 if (cmd
!= HIDIOCGUSAGE
&&
477 cmd
!= HIDIOCGUSAGES
&&
478 uref
->report_type
== HID_REPORT_TYPE_INPUT
)
481 if (uref
->report_id
== HID_REPORT_ID_UNKNOWN
) {
482 field
= hiddev_lookup_usage(hid
, uref
);
486 rinfo
.report_type
= uref
->report_type
;
487 rinfo
.report_id
= uref
->report_id
;
488 if ((report
= hiddev_lookup_report(hid
, &rinfo
)) == NULL
)
491 if (uref
->field_index
>= report
->maxfield
)
493 uref
->field_index
= array_index_nospec(uref
->field_index
,
496 field
= report
->field
[uref
->field_index
];
498 if (cmd
== HIDIOCGCOLLECTIONINDEX
) {
499 if (uref
->usage_index
>= field
->maxusage
)
502 array_index_nospec(uref
->usage_index
,
504 } else if (uref
->usage_index
>= field
->report_count
)
508 if (cmd
== HIDIOCGUSAGES
|| cmd
== HIDIOCSUSAGES
) {
509 if (uref_multi
->num_values
> HID_MAX_MULTI_USAGES
||
510 uref
->usage_index
+ uref_multi
->num_values
>
515 array_index_nospec(uref
->usage_index
,
516 field
->report_count
-
517 uref_multi
->num_values
);
522 uref
->value
= field
->value
[uref
->usage_index
];
523 if (copy_to_user(user_arg
, uref
, sizeof(*uref
)))
528 field
->value
[uref
->usage_index
] = uref
->value
;
531 case HIDIOCGCOLLECTIONINDEX
:
532 i
= field
->usage
[uref
->usage_index
].collection_index
;
536 for (i
= 0; i
< uref_multi
->num_values
; i
++)
537 uref_multi
->values
[i
] =
538 field
->value
[uref
->usage_index
+ i
];
539 if (copy_to_user(user_arg
, uref_multi
,
540 sizeof(*uref_multi
)))
544 for (i
= 0; i
< uref_multi
->num_values
; i
++)
545 field
->value
[uref
->usage_index
+ i
] =
546 uref_multi
->values
[i
];
562 static noinline
int hiddev_ioctl_string(struct hiddev
*hiddev
, unsigned int cmd
, void __user
*user_arg
)
564 struct hid_device
*hid
= hiddev
->hid
;
565 struct usb_device
*dev
= hid_to_usb_dev(hid
);
569 if (get_user(idx
, (int __user
*)user_arg
))
572 if ((buf
= kmalloc(HID_STRING_SIZE
, GFP_KERNEL
)) == NULL
)
575 if ((len
= usb_string(dev
, idx
, buf
, HID_STRING_SIZE
-1)) < 0) {
580 if (copy_to_user(user_arg
+sizeof(int), buf
, len
+1)) {
590 static long hiddev_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
592 struct hiddev_list
*list
= file
->private_data
;
593 struct hiddev
*hiddev
= list
->hiddev
;
594 struct hid_device
*hid
;
595 struct hiddev_collection_info cinfo
;
596 struct hiddev_report_info rinfo
;
597 struct hiddev_field_info finfo
;
598 struct hiddev_devinfo dinfo
;
599 struct hid_report
*report
;
600 struct hid_field
*field
;
601 void __user
*user_arg
= (void __user
*)arg
;
604 /* Called without BKL by compat methods so no BKL taken */
606 mutex_lock(&hiddev
->existancelock
);
607 if (!hiddev
->exist
) {
617 r
= put_user(HID_VERSION
, (int __user
*)arg
) ?
621 case HIDIOCAPPLICATION
:
622 if (arg
>= hid
->maxapplication
)
625 for (i
= 0; i
< hid
->maxcollection
; i
++)
626 if (hid
->collection
[i
].type
==
627 HID_COLLECTION_APPLICATION
&& arg
-- == 0)
630 if (i
< hid
->maxcollection
)
631 r
= hid
->collection
[i
].usage
;
636 struct usb_device
*dev
= hid_to_usb_dev(hid
);
637 struct usbhid_device
*usbhid
= hid
->driver_data
;
639 memset(&dinfo
, 0, sizeof(dinfo
));
641 dinfo
.bustype
= BUS_USB
;
642 dinfo
.busnum
= dev
->bus
->busnum
;
643 dinfo
.devnum
= dev
->devnum
;
644 dinfo
.ifnum
= usbhid
->ifnum
;
645 dinfo
.vendor
= le16_to_cpu(dev
->descriptor
.idVendor
);
646 dinfo
.product
= le16_to_cpu(dev
->descriptor
.idProduct
);
647 dinfo
.version
= le16_to_cpu(dev
->descriptor
.bcdDevice
);
648 dinfo
.num_applications
= hid
->maxapplication
;
650 r
= copy_to_user(user_arg
, &dinfo
, sizeof(dinfo
)) ?
656 r
= put_user(list
->flags
, (int __user
*)arg
) ?
664 if (get_user(newflags
, (int __user
*)arg
)) {
669 if ((newflags
& ~HIDDEV_FLAGS
) != 0 ||
670 ((newflags
& HIDDEV_FLAG_REPORT
) != 0 &&
671 (newflags
& HIDDEV_FLAG_UREF
) == 0))
674 list
->flags
= newflags
;
681 r
= hiddev_ioctl_string(hiddev
, cmd
, user_arg
);
684 case HIDIOCINITREPORT
:
685 usbhid_init_reports(hid
);
686 hiddev
->initialized
= true;
691 if (copy_from_user(&rinfo
, user_arg
, sizeof(rinfo
))) {
696 if (rinfo
.report_type
== HID_REPORT_TYPE_OUTPUT
)
699 report
= hiddev_lookup_report(hid
, &rinfo
);
703 hid_hw_request(hid
, report
, HID_REQ_GET_REPORT
);
710 if (copy_from_user(&rinfo
, user_arg
, sizeof(rinfo
))) {
715 if (rinfo
.report_type
== HID_REPORT_TYPE_INPUT
)
718 report
= hiddev_lookup_report(hid
, &rinfo
);
722 hid_hw_request(hid
, report
, HID_REQ_SET_REPORT
);
728 case HIDIOCGREPORTINFO
:
729 if (copy_from_user(&rinfo
, user_arg
, sizeof(rinfo
))) {
734 report
= hiddev_lookup_report(hid
, &rinfo
);
738 rinfo
.num_fields
= report
->maxfield
;
740 r
= copy_to_user(user_arg
, &rinfo
, sizeof(rinfo
)) ?
744 case HIDIOCGFIELDINFO
:
745 if (copy_from_user(&finfo
, user_arg
, sizeof(finfo
))) {
750 rinfo
.report_type
= finfo
.report_type
;
751 rinfo
.report_id
= finfo
.report_id
;
753 report
= hiddev_lookup_report(hid
, &rinfo
);
757 if (finfo
.field_index
>= report
->maxfield
)
759 finfo
.field_index
= array_index_nospec(finfo
.field_index
,
762 field
= report
->field
[finfo
.field_index
];
763 memset(&finfo
, 0, sizeof(finfo
));
764 finfo
.report_type
= rinfo
.report_type
;
765 finfo
.report_id
= rinfo
.report_id
;
766 finfo
.field_index
= field
->report_count
- 1;
767 finfo
.maxusage
= field
->maxusage
;
768 finfo
.flags
= field
->flags
;
769 finfo
.physical
= field
->physical
;
770 finfo
.logical
= field
->logical
;
771 finfo
.application
= field
->application
;
772 finfo
.logical_minimum
= field
->logical_minimum
;
773 finfo
.logical_maximum
= field
->logical_maximum
;
774 finfo
.physical_minimum
= field
->physical_minimum
;
775 finfo
.physical_maximum
= field
->physical_maximum
;
776 finfo
.unit_exponent
= field
->unit_exponent
;
777 finfo
.unit
= field
->unit
;
779 r
= copy_to_user(user_arg
, &finfo
, sizeof(finfo
)) ?
789 case HIDIOCGCOLLECTIONINDEX
:
790 if (!hiddev
->initialized
) {
791 usbhid_init_reports(hid
);
792 hiddev
->initialized
= true;
794 r
= hiddev_ioctl_usage(hiddev
, cmd
, user_arg
);
797 case HIDIOCGCOLLECTIONINFO
:
798 if (copy_from_user(&cinfo
, user_arg
, sizeof(cinfo
))) {
803 if (cinfo
.index
>= hid
->maxcollection
)
805 cinfo
.index
= array_index_nospec(cinfo
.index
,
808 cinfo
.type
= hid
->collection
[cinfo
.index
].type
;
809 cinfo
.usage
= hid
->collection
[cinfo
.index
].usage
;
810 cinfo
.level
= hid
->collection
[cinfo
.index
].level
;
812 r
= copy_to_user(user_arg
, &cinfo
, sizeof(cinfo
)) ?
817 if (_IOC_TYPE(cmd
) != 'H' || _IOC_DIR(cmd
) != _IOC_READ
)
820 if (_IOC_NR(cmd
) == _IOC_NR(HIDIOCGNAME(0))) {
821 int len
= strlen(hid
->name
) + 1;
822 if (len
> _IOC_SIZE(cmd
))
823 len
= _IOC_SIZE(cmd
);
824 r
= copy_to_user(user_arg
, hid
->name
, len
) ?
829 if (_IOC_NR(cmd
) == _IOC_NR(HIDIOCGPHYS(0))) {
830 int len
= strlen(hid
->phys
) + 1;
831 if (len
> _IOC_SIZE(cmd
))
832 len
= _IOC_SIZE(cmd
);
833 r
= copy_to_user(user_arg
, hid
->phys
, len
) ?
840 mutex_unlock(&hiddev
->existancelock
);
844 static const struct file_operations hiddev_fops
= {
845 .owner
= THIS_MODULE
,
847 .write
= hiddev_write
,
850 .release
= hiddev_release
,
851 .unlocked_ioctl
= hiddev_ioctl
,
852 .fasync
= hiddev_fasync
,
853 .compat_ioctl
= compat_ptr_ioctl
,
854 .llseek
= noop_llseek
,
857 static char *hiddev_devnode(struct device
*dev
, umode_t
*mode
)
859 return kasprintf(GFP_KERNEL
, "usb/%s", dev_name(dev
));
862 static struct usb_class_driver hiddev_class
= {
864 .devnode
= hiddev_devnode
,
865 .fops
= &hiddev_fops
,
866 .minor_base
= HIDDEV_MINOR_BASE
,
870 * This is where hid.c calls us to connect a hid device to the hiddev driver
872 int hiddev_connect(struct hid_device
*hid
, unsigned int force
)
874 struct hiddev
*hiddev
;
875 struct usbhid_device
*usbhid
= hid
->driver_data
;
880 for (i
= 0; i
< hid
->maxcollection
; i
++)
881 if (hid
->collection
[i
].type
==
882 HID_COLLECTION_APPLICATION
&&
883 !IS_INPUT_APPLICATION(hid
->collection
[i
].usage
))
886 if (i
== hid
->maxcollection
)
890 if (!(hiddev
= kzalloc(sizeof(struct hiddev
), GFP_KERNEL
)))
893 init_waitqueue_head(&hiddev
->wait
);
894 INIT_LIST_HEAD(&hiddev
->list
);
895 spin_lock_init(&hiddev
->list_lock
);
896 mutex_init(&hiddev
->existancelock
);
897 hid
->hiddev
= hiddev
;
900 retval
= usb_register_dev(usbhid
->intf
, &hiddev_class
);
902 hid_err(hid
, "Not able to get a minor for this device\n");
909 * If HID_QUIRK_NO_INIT_REPORTS is set, make sure we don't initialize
912 hiddev
->initialized
= hid
->quirks
& HID_QUIRK_NO_INIT_REPORTS
;
914 hiddev
->minor
= usbhid
->intf
->minor
;
920 * This is where hid.c calls us to disconnect a hiddev device from the
921 * corresponding hid device (usually because the usb device has disconnected)
923 static struct usb_class_driver hiddev_class
;
924 void hiddev_disconnect(struct hid_device
*hid
)
926 struct hiddev
*hiddev
= hid
->hiddev
;
927 struct usbhid_device
*usbhid
= hid
->driver_data
;
929 usb_deregister_dev(usbhid
->intf
, &hiddev_class
);
931 mutex_lock(&hiddev
->existancelock
);
935 mutex_unlock(&hiddev
->existancelock
);
936 hid_hw_close(hiddev
->hid
);
937 wake_up_interruptible(&hiddev
->wait
);
939 mutex_unlock(&hiddev
->existancelock
);