Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2001 Paul Stewart |
| 3 | * Copyright (c) 2001 Vojtech Pavlik |
| 4 | * |
| 5 | * HID char devices, giving access to raw HID device events. |
| 6 | * |
| 7 | */ |
| 8 | |
| 9 | /* |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 23 | * |
| 24 | * Should you need to contact me, the author, you can do so either by |
| 25 | * e-mail - mail your message to Paul Stewart <stewart@wetlogic.net> |
| 26 | */ |
| 27 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <linux/poll.h> |
| 29 | #include <linux/slab.h> |
| 30 | #include <linux/module.h> |
| 31 | #include <linux/init.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <linux/input.h> |
| 33 | #include <linux/usb.h> |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 34 | #include <linux/hid.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include <linux/hiddev.h> |
Philip Langdale | bb6c8d8 | 2007-10-14 12:03:58 +0200 | [diff] [blame] | 36 | #include <linux/compat.h> |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 37 | #include "usbhid.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
| 39 | #ifdef CONFIG_USB_DYNAMIC_MINORS |
| 40 | #define HIDDEV_MINOR_BASE 0 |
| 41 | #define HIDDEV_MINORS 256 |
| 42 | #else |
| 43 | #define HIDDEV_MINOR_BASE 96 |
| 44 | #define HIDDEV_MINORS 16 |
| 45 | #endif |
Jiri Kosina | affbb8c | 2009-08-20 12:04:14 +0200 | [diff] [blame] | 46 | #define HIDDEV_BUFFER_SIZE 2048 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
| 48 | struct hiddev { |
| 49 | int exist; |
| 50 | int open; |
Oliver Neukum | 0790340 | 2008-12-16 10:55:15 +0100 | [diff] [blame] | 51 | struct mutex existancelock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | wait_queue_head_t wait; |
| 53 | struct hid_device *hid; |
Dmitry Torokhov | 826d598 | 2006-07-19 01:09:10 -0400 | [diff] [blame] | 54 | struct list_head list; |
Jiri Kosina | cdcb44e | 2007-05-10 08:45:56 +0200 | [diff] [blame] | 55 | spinlock_t list_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | struct hiddev_list { |
| 59 | struct hiddev_usage_ref buffer[HIDDEV_BUFFER_SIZE]; |
| 60 | int head; |
| 61 | int tail; |
| 62 | unsigned flags; |
| 63 | struct fasync_struct *fasync; |
| 64 | struct hiddev *hiddev; |
Dmitry Torokhov | 826d598 | 2006-07-19 01:09:10 -0400 | [diff] [blame] | 65 | struct list_head node; |
Oliver Neukum | 0790340 | 2008-12-16 10:55:15 +0100 | [diff] [blame] | 66 | struct mutex thread_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | }; |
| 68 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | /* |
| 70 | * Find a report, given the report's type and ID. The ID can be specified |
| 71 | * indirectly by REPORT_ID_FIRST (which returns the first report of the given |
| 72 | * type) or by (REPORT_ID_NEXT | old_id), which returns the next report of the |
| 73 | * given type which follows old_id. |
| 74 | */ |
| 75 | static struct hid_report * |
| 76 | hiddev_lookup_report(struct hid_device *hid, struct hiddev_report_info *rinfo) |
| 77 | { |
Dmitry Torokhov | 826d598 | 2006-07-19 01:09:10 -0400 | [diff] [blame] | 78 | unsigned int flags = rinfo->report_id & ~HID_REPORT_ID_MASK; |
| 79 | unsigned int rid = rinfo->report_id & HID_REPORT_ID_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | struct hid_report_enum *report_enum; |
Dmitry Torokhov | 826d598 | 2006-07-19 01:09:10 -0400 | [diff] [blame] | 81 | struct hid_report *report; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | struct list_head *list; |
| 83 | |
| 84 | if (rinfo->report_type < HID_REPORT_TYPE_MIN || |
Dmitry Torokhov | 826d598 | 2006-07-19 01:09:10 -0400 | [diff] [blame] | 85 | rinfo->report_type > HID_REPORT_TYPE_MAX) |
| 86 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | |
| 88 | report_enum = hid->report_enum + |
| 89 | (rinfo->report_type - HID_REPORT_TYPE_MIN); |
| 90 | |
| 91 | switch (flags) { |
| 92 | case 0: /* Nothing to do -- report_id is already set correctly */ |
| 93 | break; |
| 94 | |
| 95 | case HID_REPORT_ID_FIRST: |
Dmitry Torokhov | 826d598 | 2006-07-19 01:09:10 -0400 | [diff] [blame] | 96 | if (list_empty(&report_enum->report_list)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | return NULL; |
Dmitry Torokhov | 826d598 | 2006-07-19 01:09:10 -0400 | [diff] [blame] | 98 | |
| 99 | list = report_enum->report_list.next; |
| 100 | report = list_entry(list, struct hid_report, list); |
| 101 | rinfo->report_id = report->id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | break; |
Dmitry Torokhov | 05f091a | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 103 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | case HID_REPORT_ID_NEXT: |
Dmitry Torokhov | 826d598 | 2006-07-19 01:09:10 -0400 | [diff] [blame] | 105 | report = report_enum->report_id_hash[rid]; |
| 106 | if (!report) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | return NULL; |
Dmitry Torokhov | 826d598 | 2006-07-19 01:09:10 -0400 | [diff] [blame] | 108 | |
| 109 | list = report->list.next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | if (list == &report_enum->report_list) |
| 111 | return NULL; |
Dmitry Torokhov | 826d598 | 2006-07-19 01:09:10 -0400 | [diff] [blame] | 112 | |
| 113 | report = list_entry(list, struct hid_report, list); |
| 114 | rinfo->report_id = report->id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | break; |
Dmitry Torokhov | 05f091a | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 116 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | default: |
| 118 | return NULL; |
| 119 | } |
| 120 | |
| 121 | return report_enum->report_id_hash[rinfo->report_id]; |
| 122 | } |
| 123 | |
| 124 | /* |
| 125 | * Perform an exhaustive search of the report table for a usage, given its |
| 126 | * type and usage id. |
| 127 | */ |
| 128 | static struct hid_field * |
| 129 | hiddev_lookup_usage(struct hid_device *hid, struct hiddev_usage_ref *uref) |
| 130 | { |
| 131 | int i, j; |
| 132 | struct hid_report *report; |
| 133 | struct hid_report_enum *report_enum; |
| 134 | struct hid_field *field; |
| 135 | |
| 136 | if (uref->report_type < HID_REPORT_TYPE_MIN || |
Dmitry Torokhov | 826d598 | 2006-07-19 01:09:10 -0400 | [diff] [blame] | 137 | uref->report_type > HID_REPORT_TYPE_MAX) |
| 138 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | |
| 140 | report_enum = hid->report_enum + |
| 141 | (uref->report_type - HID_REPORT_TYPE_MIN); |
| 142 | |
Dmitry Torokhov | 826d598 | 2006-07-19 01:09:10 -0400 | [diff] [blame] | 143 | list_for_each_entry(report, &report_enum->report_list, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | for (i = 0; i < report->maxfield; i++) { |
| 145 | field = report->field[i]; |
| 146 | for (j = 0; j < field->maxusage; j++) { |
| 147 | if (field->usage[j].hid == uref->usage_code) { |
| 148 | uref->report_id = report->id; |
| 149 | uref->field_index = i; |
| 150 | uref->usage_index = j; |
| 151 | return field; |
| 152 | } |
| 153 | } |
| 154 | } |
Dmitry Torokhov | 826d598 | 2006-07-19 01:09:10 -0400 | [diff] [blame] | 155 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | |
| 157 | return NULL; |
| 158 | } |
| 159 | |
| 160 | static void hiddev_send_event(struct hid_device *hid, |
| 161 | struct hiddev_usage_ref *uref) |
| 162 | { |
| 163 | struct hiddev *hiddev = hid->hiddev; |
Dmitry Torokhov | 826d598 | 2006-07-19 01:09:10 -0400 | [diff] [blame] | 164 | struct hiddev_list *list; |
Jiri Kosina | cdcb44e | 2007-05-10 08:45:56 +0200 | [diff] [blame] | 165 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | |
Jiri Kosina | cdcb44e | 2007-05-10 08:45:56 +0200 | [diff] [blame] | 167 | spin_lock_irqsave(&hiddev->list_lock, flags); |
Dmitry Torokhov | 826d598 | 2006-07-19 01:09:10 -0400 | [diff] [blame] | 168 | list_for_each_entry(list, &hiddev->list, node) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | if (uref->field_index != HID_FIELD_INDEX_NONE || |
| 170 | (list->flags & HIDDEV_FLAG_REPORT) != 0) { |
| 171 | list->buffer[list->head] = *uref; |
Dmitry Torokhov | 05f091a | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 172 | list->head = (list->head + 1) & |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | (HIDDEV_BUFFER_SIZE - 1); |
| 174 | kill_fasync(&list->fasync, SIGIO, POLL_IN); |
| 175 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | } |
Jiri Kosina | cdcb44e | 2007-05-10 08:45:56 +0200 | [diff] [blame] | 177 | spin_unlock_irqrestore(&hiddev->list_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | |
| 179 | wake_up_interruptible(&hiddev->wait); |
| 180 | } |
| 181 | |
| 182 | /* |
| 183 | * This is where hid.c calls into hiddev to pass an event that occurred over |
| 184 | * the interrupt pipe |
| 185 | */ |
| 186 | void hiddev_hid_event(struct hid_device *hid, struct hid_field *field, |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 187 | struct hid_usage *usage, __s32 value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | { |
| 189 | unsigned type = field->report_type; |
| 190 | struct hiddev_usage_ref uref; |
| 191 | |
Dmitry Torokhov | 05f091a | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 192 | uref.report_type = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | (type == HID_INPUT_REPORT) ? HID_REPORT_TYPE_INPUT : |
Dmitry Torokhov | 05f091a | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 194 | ((type == HID_OUTPUT_REPORT) ? HID_REPORT_TYPE_OUTPUT : |
Dmitry Torokhov | 826d598 | 2006-07-19 01:09:10 -0400 | [diff] [blame] | 195 | ((type == HID_FEATURE_REPORT) ? HID_REPORT_TYPE_FEATURE : 0)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | uref.report_id = field->report->id; |
| 197 | uref.field_index = field->index; |
| 198 | uref.usage_index = (usage - field->usage); |
| 199 | uref.usage_code = usage->hid; |
| 200 | uref.value = value; |
| 201 | |
| 202 | hiddev_send_event(hid, &uref); |
| 203 | } |
Jiri Kosina | 229695e | 2006-12-08 18:40:53 +0100 | [diff] [blame] | 204 | EXPORT_SYMBOL_GPL(hiddev_hid_event); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | |
| 206 | void hiddev_report_event(struct hid_device *hid, struct hid_report *report) |
| 207 | { |
| 208 | unsigned type = report->type; |
| 209 | struct hiddev_usage_ref uref; |
| 210 | |
| 211 | memset(&uref, 0, sizeof(uref)); |
Dmitry Torokhov | 05f091a | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 212 | uref.report_type = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | (type == HID_INPUT_REPORT) ? HID_REPORT_TYPE_INPUT : |
Dmitry Torokhov | 05f091a | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 214 | ((type == HID_OUTPUT_REPORT) ? HID_REPORT_TYPE_OUTPUT : |
Dmitry Torokhov | 826d598 | 2006-07-19 01:09:10 -0400 | [diff] [blame] | 215 | ((type == HID_FEATURE_REPORT) ? HID_REPORT_TYPE_FEATURE : 0)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | uref.report_id = report->id; |
| 217 | uref.field_index = HID_FIELD_INDEX_NONE; |
| 218 | |
| 219 | hiddev_send_event(hid, &uref); |
| 220 | } |
Jiri Kosina | aa8de2f | 2006-12-08 18:41:17 +0100 | [diff] [blame] | 221 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | /* |
| 223 | * fasync file op |
| 224 | */ |
| 225 | static int hiddev_fasync(int fd, struct file *file, int on) |
| 226 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | struct hiddev_list *list = file->private_data; |
Dmitry Torokhov | 826d598 | 2006-07-19 01:09:10 -0400 | [diff] [blame] | 228 | |
Jonathan Corbet | 60aa492 | 2009-02-01 14:52:56 -0700 | [diff] [blame] | 229 | return fasync_helper(fd, file, on, &list->fasync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | |
| 233 | /* |
| 234 | * release file op |
| 235 | */ |
| 236 | static int hiddev_release(struct inode * inode, struct file * file) |
| 237 | { |
| 238 | struct hiddev_list *list = file->private_data; |
Jiri Kosina | cdcb44e | 2007-05-10 08:45:56 +0200 | [diff] [blame] | 239 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | |
Jiri Kosina | cdcb44e | 2007-05-10 08:45:56 +0200 | [diff] [blame] | 241 | spin_lock_irqsave(&list->hiddev->list_lock, flags); |
Dmitry Torokhov | 826d598 | 2006-07-19 01:09:10 -0400 | [diff] [blame] | 242 | list_del(&list->node); |
Jiri Kosina | cdcb44e | 2007-05-10 08:45:56 +0200 | [diff] [blame] | 243 | spin_unlock_irqrestore(&list->hiddev->list_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | |
Jiri Kosina | 6cb4b04 | 2011-05-20 10:50:13 +0200 | [diff] [blame] | 245 | mutex_lock(&list->hiddev->existancelock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | if (!--list->hiddev->open) { |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 247 | if (list->hiddev->exist) { |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 248 | usbhid_close(list->hiddev->hid); |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 249 | usbhid_put_power(list->hiddev->hid); |
| 250 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | kfree(list->hiddev); |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 252 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | kfree(list); |
Jiri Kosina | 6cb4b04 | 2011-05-20 10:50:13 +0200 | [diff] [blame] | 256 | mutex_unlock(&list->hiddev->existancelock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | |
| 258 | return 0; |
| 259 | } |
| 260 | |
| 261 | /* |
| 262 | * open file op |
| 263 | */ |
Dmitry Torokhov | 826d598 | 2006-07-19 01:09:10 -0400 | [diff] [blame] | 264 | static int hiddev_open(struct inode *inode, struct file *file) |
| 265 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | struct hiddev_list *list; |
Arnd Bergmann | bd25f4d | 2010-07-11 15:34:05 +0200 | [diff] [blame] | 267 | struct usb_interface *intf; |
Jiri Kosina | 9c9e54a | 2010-08-13 12:19:45 +0200 | [diff] [blame] | 268 | struct hid_device *hid; |
Arnd Bergmann | bd25f4d | 2010-07-11 15:34:05 +0200 | [diff] [blame] | 269 | struct hiddev *hiddev; |
| 270 | int res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | |
Guillaume Chazarain | 8fe294c | 2010-09-12 21:32:35 +0200 | [diff] [blame] | 272 | intf = usbhid_find_interface(iminor(inode)); |
Arnd Bergmann | bd25f4d | 2010-07-11 15:34:05 +0200 | [diff] [blame] | 273 | if (!intf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | return -ENODEV; |
Jiri Kosina | 9c9e54a | 2010-08-13 12:19:45 +0200 | [diff] [blame] | 275 | hid = usb_get_intfdata(intf); |
| 276 | hiddev = hid->hiddev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | |
Oliver Neukum | bbdb7da | 2006-01-06 20:54:29 +0100 | [diff] [blame] | 278 | if (!(list = kzalloc(sizeof(struct hiddev_list), GFP_KERNEL))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | return -ENOMEM; |
Oliver Neukum | 0790340 | 2008-12-16 10:55:15 +0100 | [diff] [blame] | 280 | mutex_init(&list->thread_lock); |
Arnd Bergmann | bd25f4d | 2010-07-11 15:34:05 +0200 | [diff] [blame] | 281 | list->hiddev = hiddev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | file->private_data = list; |
| 283 | |
Oliver Neukum | 0790340 | 2008-12-16 10:55:15 +0100 | [diff] [blame] | 284 | /* |
| 285 | * no need for locking because the USB major number |
| 286 | * is shared which usbcore guards against disconnect |
| 287 | */ |
| 288 | if (list->hiddev->exist) { |
| 289 | if (!list->hiddev->open++) { |
Arnd Bergmann | bd25f4d | 2010-07-11 15:34:05 +0200 | [diff] [blame] | 290 | res = usbhid_open(hiddev->hid); |
Oliver Neukum | 0790340 | 2008-12-16 10:55:15 +0100 | [diff] [blame] | 291 | if (res < 0) { |
| 292 | res = -EIO; |
| 293 | goto bail; |
| 294 | } |
| 295 | } |
| 296 | } else { |
| 297 | res = -ENODEV; |
| 298 | goto bail; |
| 299 | } |
| 300 | |
| 301 | spin_lock_irq(&list->hiddev->list_lock); |
Arnd Bergmann | bd25f4d | 2010-07-11 15:34:05 +0200 | [diff] [blame] | 302 | list_add_tail(&list->node, &hiddev->list); |
Oliver Neukum | 0790340 | 2008-12-16 10:55:15 +0100 | [diff] [blame] | 303 | spin_unlock_irq(&list->hiddev->list_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | |
Jiri Kosina | 6cb4b04 | 2011-05-20 10:50:13 +0200 | [diff] [blame] | 305 | mutex_lock(&hiddev->existancelock); |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 306 | if (!list->hiddev->open++) |
| 307 | if (list->hiddev->exist) { |
Arnd Bergmann | bd25f4d | 2010-07-11 15:34:05 +0200 | [diff] [blame] | 308 | struct hid_device *hid = hiddev->hid; |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 309 | res = usbhid_get_power(hid); |
| 310 | if (res < 0) { |
| 311 | res = -EIO; |
Jiri Kosina | 6cb4b04 | 2011-05-20 10:50:13 +0200 | [diff] [blame] | 312 | goto bail_unlock; |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 313 | } |
| 314 | usbhid_open(hid); |
| 315 | } |
Jiri Kosina | 6cb4b04 | 2011-05-20 10:50:13 +0200 | [diff] [blame] | 316 | mutex_unlock(&hiddev->existancelock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | return 0; |
Jiri Kosina | 6cb4b04 | 2011-05-20 10:50:13 +0200 | [diff] [blame] | 318 | bail_unlock: |
| 319 | mutex_unlock(&hiddev->existancelock); |
Oliver Neukum | 0790340 | 2008-12-16 10:55:15 +0100 | [diff] [blame] | 320 | bail: |
| 321 | file->private_data = NULL; |
Johannes Weiner | 48e7a3c | 2009-03-10 22:43:56 +0100 | [diff] [blame] | 322 | kfree(list); |
Oliver Neukum | 0790340 | 2008-12-16 10:55:15 +0100 | [diff] [blame] | 323 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | /* |
| 327 | * "write" file op |
| 328 | */ |
| 329 | static ssize_t hiddev_write(struct file * file, const char __user * buffer, size_t count, loff_t *ppos) |
| 330 | { |
| 331 | return -EINVAL; |
| 332 | } |
| 333 | |
| 334 | /* |
| 335 | * "read" file op |
| 336 | */ |
| 337 | static ssize_t hiddev_read(struct file * file, char __user * buffer, size_t count, loff_t *ppos) |
| 338 | { |
Johannes Weiner | 96fe2ab | 2009-03-10 22:44:01 +0100 | [diff] [blame] | 339 | DEFINE_WAIT(wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | struct hiddev_list *list = file->private_data; |
| 341 | int event_size; |
Oliver Neukum | 0790340 | 2008-12-16 10:55:15 +0100 | [diff] [blame] | 342 | int retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | |
| 344 | event_size = ((list->flags & HIDDEV_FLAG_UREF) != 0) ? |
| 345 | sizeof(struct hiddev_usage_ref) : sizeof(struct hiddev_event); |
| 346 | |
| 347 | if (count < event_size) |
| 348 | return 0; |
| 349 | |
Oliver Neukum | 0790340 | 2008-12-16 10:55:15 +0100 | [diff] [blame] | 350 | /* lock against other threads */ |
| 351 | retval = mutex_lock_interruptible(&list->thread_lock); |
| 352 | if (retval) |
| 353 | return -ERESTARTSYS; |
| 354 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | while (retval == 0) { |
| 356 | if (list->head == list->tail) { |
Oliver Neukum | 0790340 | 2008-12-16 10:55:15 +0100 | [diff] [blame] | 357 | prepare_to_wait(&list->hiddev->wait, &wait, TASK_INTERRUPTIBLE); |
Dmitry Torokhov | 05f091a | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 358 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | while (list->head == list->tail) { |
| 360 | if (file->f_flags & O_NONBLOCK) { |
| 361 | retval = -EAGAIN; |
| 362 | break; |
| 363 | } |
| 364 | if (signal_pending(current)) { |
| 365 | retval = -ERESTARTSYS; |
| 366 | break; |
| 367 | } |
| 368 | if (!list->hiddev->exist) { |
| 369 | retval = -EIO; |
| 370 | break; |
| 371 | } |
Dmitry Torokhov | 05f091a | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 372 | |
Oliver Neukum | 0790340 | 2008-12-16 10:55:15 +0100 | [diff] [blame] | 373 | /* let O_NONBLOCK tasks run */ |
| 374 | mutex_unlock(&list->thread_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | schedule(); |
Peter Waechtler | 06268b2 | 2011-04-28 20:53:58 +0200 | [diff] [blame] | 376 | if (mutex_lock_interruptible(&list->thread_lock)) { |
| 377 | finish_wait(&list->hiddev->wait, &wait); |
Oliver Neukum | 0790340 | 2008-12-16 10:55:15 +0100 | [diff] [blame] | 378 | return -EINTR; |
Peter Waechtler | 06268b2 | 2011-04-28 20:53:58 +0200 | [diff] [blame] | 379 | } |
Micon, David | 48d7055 | 2006-05-20 14:59:59 -0700 | [diff] [blame] | 380 | set_current_state(TASK_INTERRUPTIBLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | } |
Oliver Neukum | 0790340 | 2008-12-16 10:55:15 +0100 | [diff] [blame] | 382 | finish_wait(&list->hiddev->wait, &wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | } |
| 385 | |
Oliver Neukum | 0790340 | 2008-12-16 10:55:15 +0100 | [diff] [blame] | 386 | if (retval) { |
| 387 | mutex_unlock(&list->thread_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | return retval; |
Oliver Neukum | 0790340 | 2008-12-16 10:55:15 +0100 | [diff] [blame] | 389 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | |
| 391 | |
Dmitry Torokhov | 05f091a | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 392 | while (list->head != list->tail && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | retval + event_size <= count) { |
| 394 | if ((list->flags & HIDDEV_FLAG_UREF) == 0) { |
Oliver Neukum | 0790340 | 2008-12-16 10:55:15 +0100 | [diff] [blame] | 395 | if (list->buffer[list->tail].field_index != HID_FIELD_INDEX_NONE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | struct hiddev_event event; |
Oliver Neukum | 0790340 | 2008-12-16 10:55:15 +0100 | [diff] [blame] | 397 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | event.hid = list->buffer[list->tail].usage_code; |
| 399 | event.value = list->buffer[list->tail].value; |
Oliver Neukum | 0790340 | 2008-12-16 10:55:15 +0100 | [diff] [blame] | 400 | if (copy_to_user(buffer + retval, &event, sizeof(struct hiddev_event))) { |
| 401 | mutex_unlock(&list->thread_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | return -EFAULT; |
Oliver Neukum | 0790340 | 2008-12-16 10:55:15 +0100 | [diff] [blame] | 403 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | retval += sizeof(struct hiddev_event); |
| 405 | } |
| 406 | } else { |
| 407 | if (list->buffer[list->tail].field_index != HID_FIELD_INDEX_NONE || |
| 408 | (list->flags & HIDDEV_FLAG_REPORT) != 0) { |
Oliver Neukum | 0790340 | 2008-12-16 10:55:15 +0100 | [diff] [blame] | 409 | |
| 410 | if (copy_to_user(buffer + retval, list->buffer + list->tail, sizeof(struct hiddev_usage_ref))) { |
| 411 | mutex_unlock(&list->thread_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | return -EFAULT; |
Oliver Neukum | 0790340 | 2008-12-16 10:55:15 +0100 | [diff] [blame] | 413 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | retval += sizeof(struct hiddev_usage_ref); |
| 415 | } |
| 416 | } |
| 417 | list->tail = (list->tail + 1) & (HIDDEV_BUFFER_SIZE - 1); |
| 418 | } |
| 419 | |
| 420 | } |
Oliver Neukum | 0790340 | 2008-12-16 10:55:15 +0100 | [diff] [blame] | 421 | mutex_unlock(&list->thread_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | |
| 423 | return retval; |
| 424 | } |
| 425 | |
| 426 | /* |
| 427 | * "poll" file op |
| 428 | * No kernel lock - fine |
| 429 | */ |
| 430 | static unsigned int hiddev_poll(struct file *file, poll_table *wait) |
| 431 | { |
| 432 | struct hiddev_list *list = file->private_data; |
Dmitry Torokhov | 826d598 | 2006-07-19 01:09:10 -0400 | [diff] [blame] | 433 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | poll_wait(file, &list->hiddev->wait, wait); |
| 435 | if (list->head != list->tail) |
| 436 | return POLLIN | POLLRDNORM; |
| 437 | if (!list->hiddev->exist) |
| 438 | return POLLERR | POLLHUP; |
| 439 | return 0; |
| 440 | } |
| 441 | |
| 442 | /* |
| 443 | * "ioctl" file op |
| 444 | */ |
Jean Delvare | cf2a299 | 2008-03-03 11:48:43 +0100 | [diff] [blame] | 445 | static noinline int hiddev_ioctl_usage(struct hiddev *hiddev, unsigned int cmd, void __user *user_arg) |
| 446 | { |
| 447 | struct hid_device *hid = hiddev->hid; |
| 448 | struct hiddev_report_info rinfo; |
| 449 | struct hiddev_usage_ref_multi *uref_multi = NULL; |
| 450 | struct hiddev_usage_ref *uref; |
| 451 | struct hid_report *report; |
| 452 | struct hid_field *field; |
| 453 | int i; |
| 454 | |
| 455 | uref_multi = kmalloc(sizeof(struct hiddev_usage_ref_multi), GFP_KERNEL); |
| 456 | if (!uref_multi) |
| 457 | return -ENOMEM; |
| 458 | uref = &uref_multi->uref; |
| 459 | if (cmd == HIDIOCGUSAGES || cmd == HIDIOCSUSAGES) { |
| 460 | if (copy_from_user(uref_multi, user_arg, |
| 461 | sizeof(*uref_multi))) |
| 462 | goto fault; |
| 463 | } else { |
| 464 | if (copy_from_user(uref, user_arg, sizeof(*uref))) |
| 465 | goto fault; |
| 466 | } |
| 467 | |
| 468 | switch (cmd) { |
| 469 | case HIDIOCGUCODE: |
| 470 | rinfo.report_type = uref->report_type; |
| 471 | rinfo.report_id = uref->report_id; |
| 472 | if ((report = hiddev_lookup_report(hid, &rinfo)) == NULL) |
| 473 | goto inval; |
| 474 | |
| 475 | if (uref->field_index >= report->maxfield) |
| 476 | goto inval; |
| 477 | |
| 478 | field = report->field[uref->field_index]; |
| 479 | if (uref->usage_index >= field->maxusage) |
| 480 | goto inval; |
| 481 | |
| 482 | uref->usage_code = field->usage[uref->usage_index].hid; |
| 483 | |
| 484 | if (copy_to_user(user_arg, uref, sizeof(*uref))) |
| 485 | goto fault; |
| 486 | |
Jiri Slaby | eb99108 | 2008-10-23 01:47:34 +0200 | [diff] [blame] | 487 | goto goodreturn; |
Jean Delvare | cf2a299 | 2008-03-03 11:48:43 +0100 | [diff] [blame] | 488 | |
| 489 | default: |
| 490 | if (cmd != HIDIOCGUSAGE && |
| 491 | cmd != HIDIOCGUSAGES && |
| 492 | uref->report_type == HID_REPORT_TYPE_INPUT) |
| 493 | goto inval; |
| 494 | |
| 495 | if (uref->report_id == HID_REPORT_ID_UNKNOWN) { |
| 496 | field = hiddev_lookup_usage(hid, uref); |
| 497 | if (field == NULL) |
| 498 | goto inval; |
| 499 | } else { |
| 500 | rinfo.report_type = uref->report_type; |
| 501 | rinfo.report_id = uref->report_id; |
| 502 | if ((report = hiddev_lookup_report(hid, &rinfo)) == NULL) |
| 503 | goto inval; |
| 504 | |
| 505 | if (uref->field_index >= report->maxfield) |
| 506 | goto inval; |
| 507 | |
| 508 | field = report->field[uref->field_index]; |
| 509 | |
| 510 | if (cmd == HIDIOCGCOLLECTIONINDEX) { |
| 511 | if (uref->usage_index >= field->maxusage) |
| 512 | goto inval; |
| 513 | } else if (uref->usage_index >= field->report_count) |
| 514 | goto inval; |
| 515 | |
| 516 | else if ((cmd == HIDIOCGUSAGES || cmd == HIDIOCSUSAGES) && |
| 517 | (uref_multi->num_values > HID_MAX_MULTI_USAGES || |
| 518 | uref->usage_index + uref_multi->num_values > field->report_count)) |
| 519 | goto inval; |
Dan Carpenter | ac065bf | 2011-03-26 04:47:35 +0300 | [diff] [blame] | 520 | } |
Jean Delvare | cf2a299 | 2008-03-03 11:48:43 +0100 | [diff] [blame] | 521 | |
| 522 | switch (cmd) { |
| 523 | case HIDIOCGUSAGE: |
| 524 | uref->value = field->value[uref->usage_index]; |
| 525 | if (copy_to_user(user_arg, uref, sizeof(*uref))) |
| 526 | goto fault; |
| 527 | goto goodreturn; |
| 528 | |
| 529 | case HIDIOCSUSAGE: |
| 530 | field->value[uref->usage_index] = uref->value; |
| 531 | goto goodreturn; |
| 532 | |
| 533 | case HIDIOCGCOLLECTIONINDEX: |
Jiri Slaby | 4859484 | 2009-06-19 23:24:11 +0200 | [diff] [blame] | 534 | i = field->usage[uref->usage_index].collection_index; |
Jean Delvare | cf2a299 | 2008-03-03 11:48:43 +0100 | [diff] [blame] | 535 | kfree(uref_multi); |
Jiri Slaby | 4859484 | 2009-06-19 23:24:11 +0200 | [diff] [blame] | 536 | return i; |
Jean Delvare | cf2a299 | 2008-03-03 11:48:43 +0100 | [diff] [blame] | 537 | case HIDIOCGUSAGES: |
| 538 | for (i = 0; i < uref_multi->num_values; i++) |
| 539 | uref_multi->values[i] = |
| 540 | field->value[uref->usage_index + i]; |
| 541 | if (copy_to_user(user_arg, uref_multi, |
| 542 | sizeof(*uref_multi))) |
| 543 | goto fault; |
| 544 | goto goodreturn; |
| 545 | case HIDIOCSUSAGES: |
| 546 | for (i = 0; i < uref_multi->num_values; i++) |
| 547 | field->value[uref->usage_index + i] = |
| 548 | uref_multi->values[i]; |
| 549 | goto goodreturn; |
| 550 | } |
| 551 | |
| 552 | goodreturn: |
| 553 | kfree(uref_multi); |
| 554 | return 0; |
| 555 | fault: |
| 556 | kfree(uref_multi); |
| 557 | return -EFAULT; |
| 558 | inval: |
| 559 | kfree(uref_multi); |
| 560 | return -EINVAL; |
| 561 | } |
| 562 | } |
| 563 | |
| 564 | static noinline int hiddev_ioctl_string(struct hiddev *hiddev, unsigned int cmd, void __user *user_arg) |
| 565 | { |
| 566 | struct hid_device *hid = hiddev->hid; |
| 567 | struct usb_device *dev = hid_to_usb_dev(hid); |
| 568 | int idx, len; |
| 569 | char *buf; |
| 570 | |
| 571 | if (get_user(idx, (int __user *)user_arg)) |
| 572 | return -EFAULT; |
| 573 | |
| 574 | if ((buf = kmalloc(HID_STRING_SIZE, GFP_KERNEL)) == NULL) |
| 575 | return -ENOMEM; |
| 576 | |
| 577 | if ((len = usb_string(dev, idx, buf, HID_STRING_SIZE-1)) < 0) { |
| 578 | kfree(buf); |
| 579 | return -EINVAL; |
| 580 | } |
| 581 | |
| 582 | if (copy_to_user(user_arg+sizeof(int), buf, len+1)) { |
| 583 | kfree(buf); |
| 584 | return -EFAULT; |
| 585 | } |
| 586 | |
| 587 | kfree(buf); |
| 588 | |
| 589 | return len; |
| 590 | } |
| 591 | |
Alan Cox | 7961df1 | 2008-05-26 11:25:20 +0200 | [diff] [blame] | 592 | static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | { |
| 594 | struct hiddev_list *list = file->private_data; |
| 595 | struct hiddev *hiddev = list->hiddev; |
Valentine Barshak | 1a8e8fa | 2010-12-06 17:51:41 +0300 | [diff] [blame] | 596 | struct hid_device *hid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | struct hiddev_collection_info cinfo; |
| 598 | struct hiddev_report_info rinfo; |
| 599 | struct hiddev_field_info finfo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | struct hiddev_devinfo dinfo; |
| 601 | struct hid_report *report; |
| 602 | struct hid_field *field; |
| 603 | void __user *user_arg = (void __user *)arg; |
Valentine Barshak | 33d6eb5 | 2010-12-06 18:16:11 +0300 | [diff] [blame] | 604 | int i, r = -EINVAL; |
Valentine Barshak | 1a8e8fa | 2010-12-06 17:51:41 +0300 | [diff] [blame] | 605 | |
Alan Cox | 7961df1 | 2008-05-26 11:25:20 +0200 | [diff] [blame] | 606 | /* Called without BKL by compat methods so no BKL taken */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | |
Valentine Barshak | 33d6eb5 | 2010-12-06 18:16:11 +0300 | [diff] [blame] | 608 | mutex_lock(&hiddev->existancelock); |
| 609 | if (!hiddev->exist) { |
| 610 | r = -ENODEV; |
| 611 | goto ret_unlock; |
| 612 | } |
| 613 | |
| 614 | hid = hiddev->hid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | |
| 616 | switch (cmd) { |
| 617 | |
| 618 | case HIDIOCGVERSION: |
Valentine Barshak | 33d6eb5 | 2010-12-06 18:16:11 +0300 | [diff] [blame] | 619 | r = put_user(HID_VERSION, (int __user *)arg) ? |
| 620 | -EFAULT : 0; |
| 621 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | |
| 623 | case HIDIOCAPPLICATION: |
Valentine Barshak | 33d6eb5 | 2010-12-06 18:16:11 +0300 | [diff] [blame] | 624 | if (arg < 0 || arg >= hid->maxapplication) |
| 625 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | |
| 627 | for (i = 0; i < hid->maxcollection; i++) |
Dmitry Torokhov | 05f091a | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 628 | if (hid->collection[i].type == |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | HID_COLLECTION_APPLICATION && arg-- == 0) |
| 630 | break; |
Dmitry Torokhov | 05f091a | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 631 | |
Valentine Barshak | 33d6eb5 | 2010-12-06 18:16:11 +0300 | [diff] [blame] | 632 | if (i < hid->maxcollection) |
Valentine Barshak | 1a8e8fa | 2010-12-06 17:51:41 +0300 | [diff] [blame] | 633 | r = hid->collection[i].usage; |
Valentine Barshak | 33d6eb5 | 2010-12-06 18:16:11 +0300 | [diff] [blame] | 634 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | |
| 636 | case HIDIOCGDEVINFO: |
Valentine Barshak | 33d6eb5 | 2010-12-06 18:16:11 +0300 | [diff] [blame] | 637 | { |
| 638 | struct usb_device *dev = hid_to_usb_dev(hid); |
| 639 | struct usbhid_device *usbhid = hid->driver_data; |
| 640 | |
| 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; |
| 649 | |
| 650 | r = copy_to_user(user_arg, &dinfo, sizeof(dinfo)) ? |
| 651 | -EFAULT : 0; |
| 652 | break; |
Valentine Barshak | 1a8e8fa | 2010-12-06 17:51:41 +0300 | [diff] [blame] | 653 | } |
| 654 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | case HIDIOCGFLAG: |
Valentine Barshak | 33d6eb5 | 2010-12-06 18:16:11 +0300 | [diff] [blame] | 656 | r = put_user(list->flags, (int __user *)arg) ? |
| 657 | -EFAULT : 0; |
| 658 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | |
| 660 | case HIDIOCSFLAG: |
| 661 | { |
| 662 | int newflags; |
Valentine Barshak | 33d6eb5 | 2010-12-06 18:16:11 +0300 | [diff] [blame] | 663 | |
| 664 | if (get_user(newflags, (int __user *)arg)) { |
| 665 | r = -EFAULT; |
| 666 | break; |
| 667 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | |
| 669 | if ((newflags & ~HIDDEV_FLAGS) != 0 || |
| 670 | ((newflags & HIDDEV_FLAG_REPORT) != 0 && |
| 671 | (newflags & HIDDEV_FLAG_UREF) == 0)) |
Valentine Barshak | 33d6eb5 | 2010-12-06 18:16:11 +0300 | [diff] [blame] | 672 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | |
| 674 | list->flags = newflags; |
| 675 | |
Valentine Barshak | 33d6eb5 | 2010-12-06 18:16:11 +0300 | [diff] [blame] | 676 | r = 0; |
| 677 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | } |
| 679 | |
| 680 | case HIDIOCGSTRING: |
Valentine Barshak | 33d6eb5 | 2010-12-06 18:16:11 +0300 | [diff] [blame] | 681 | r = hiddev_ioctl_string(hiddev, cmd, user_arg); |
| 682 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | |
| 684 | case HIDIOCINITREPORT: |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 685 | usbhid_init_reports(hid); |
Valentine Barshak | 33d6eb5 | 2010-12-06 18:16:11 +0300 | [diff] [blame] | 686 | r = 0; |
| 687 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | |
| 689 | case HIDIOCGREPORT: |
Valentine Barshak | 33d6eb5 | 2010-12-06 18:16:11 +0300 | [diff] [blame] | 690 | if (copy_from_user(&rinfo, user_arg, sizeof(rinfo))) { |
| 691 | r = -EFAULT; |
| 692 | break; |
| 693 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | |
| 695 | if (rinfo.report_type == HID_REPORT_TYPE_OUTPUT) |
Valentine Barshak | 33d6eb5 | 2010-12-06 18:16:11 +0300 | [diff] [blame] | 696 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | |
Valentine Barshak | 1a8e8fa | 2010-12-06 17:51:41 +0300 | [diff] [blame] | 698 | report = hiddev_lookup_report(hid, &rinfo); |
Valentine Barshak | 33d6eb5 | 2010-12-06 18:16:11 +0300 | [diff] [blame] | 699 | if (report == NULL) |
| 700 | break; |
Valentine Barshak | 1a8e8fa | 2010-12-06 17:51:41 +0300 | [diff] [blame] | 701 | |
| 702 | usbhid_submit_report(hid, report, USB_DIR_IN); |
| 703 | usbhid_wait_io(hid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | |
Valentine Barshak | 33d6eb5 | 2010-12-06 18:16:11 +0300 | [diff] [blame] | 705 | r = 0; |
| 706 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | |
| 708 | case HIDIOCSREPORT: |
Valentine Barshak | 33d6eb5 | 2010-12-06 18:16:11 +0300 | [diff] [blame] | 709 | if (copy_from_user(&rinfo, user_arg, sizeof(rinfo))) { |
| 710 | r = -EFAULT; |
| 711 | break; |
| 712 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | |
| 714 | if (rinfo.report_type == HID_REPORT_TYPE_INPUT) |
Valentine Barshak | 33d6eb5 | 2010-12-06 18:16:11 +0300 | [diff] [blame] | 715 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | |
Valentine Barshak | 1a8e8fa | 2010-12-06 17:51:41 +0300 | [diff] [blame] | 717 | report = hiddev_lookup_report(hid, &rinfo); |
Valentine Barshak | 33d6eb5 | 2010-12-06 18:16:11 +0300 | [diff] [blame] | 718 | if (report == NULL) |
| 719 | break; |
Valentine Barshak | 1a8e8fa | 2010-12-06 17:51:41 +0300 | [diff] [blame] | 720 | |
| 721 | usbhid_submit_report(hid, report, USB_DIR_OUT); |
| 722 | usbhid_wait_io(hid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | |
Valentine Barshak | 33d6eb5 | 2010-12-06 18:16:11 +0300 | [diff] [blame] | 724 | r = 0; |
| 725 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | |
| 727 | case HIDIOCGREPORTINFO: |
Valentine Barshak | 33d6eb5 | 2010-12-06 18:16:11 +0300 | [diff] [blame] | 728 | if (copy_from_user(&rinfo, user_arg, sizeof(rinfo))) { |
| 729 | r = -EFAULT; |
| 730 | break; |
Valentine Barshak | 1a8e8fa | 2010-12-06 17:51:41 +0300 | [diff] [blame] | 731 | } |
| 732 | |
Valentine Barshak | 1a8e8fa | 2010-12-06 17:51:41 +0300 | [diff] [blame] | 733 | report = hiddev_lookup_report(hid, &rinfo); |
Valentine Barshak | 33d6eb5 | 2010-12-06 18:16:11 +0300 | [diff] [blame] | 734 | if (report == NULL) |
| 735 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | |
| 737 | rinfo.num_fields = report->maxfield; |
| 738 | |
Valentine Barshak | 33d6eb5 | 2010-12-06 18:16:11 +0300 | [diff] [blame] | 739 | r = copy_to_user(user_arg, &rinfo, sizeof(rinfo)) ? |
| 740 | -EFAULT : 0; |
| 741 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | |
| 743 | case HIDIOCGFIELDINFO: |
Valentine Barshak | 33d6eb5 | 2010-12-06 18:16:11 +0300 | [diff] [blame] | 744 | if (copy_from_user(&finfo, user_arg, sizeof(finfo))) { |
| 745 | r = -EFAULT; |
| 746 | break; |
| 747 | } |
| 748 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | rinfo.report_type = finfo.report_type; |
| 750 | rinfo.report_id = finfo.report_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | |
Valentine Barshak | 1a8e8fa | 2010-12-06 17:51:41 +0300 | [diff] [blame] | 752 | report = hiddev_lookup_report(hid, &rinfo); |
Valentine Barshak | 33d6eb5 | 2010-12-06 18:16:11 +0300 | [diff] [blame] | 753 | if (report == NULL) |
| 754 | break; |
Valentine Barshak | 1a8e8fa | 2010-12-06 17:51:41 +0300 | [diff] [blame] | 755 | |
Valentine Barshak | 33d6eb5 | 2010-12-06 18:16:11 +0300 | [diff] [blame] | 756 | if (finfo.field_index >= report->maxfield) |
| 757 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | |
| 759 | field = report->field[finfo.field_index]; |
| 760 | memset(&finfo, 0, sizeof(finfo)); |
| 761 | finfo.report_type = rinfo.report_type; |
| 762 | finfo.report_id = rinfo.report_id; |
| 763 | finfo.field_index = field->report_count - 1; |
| 764 | finfo.maxusage = field->maxusage; |
| 765 | finfo.flags = field->flags; |
| 766 | finfo.physical = field->physical; |
| 767 | finfo.logical = field->logical; |
| 768 | finfo.application = field->application; |
| 769 | finfo.logical_minimum = field->logical_minimum; |
| 770 | finfo.logical_maximum = field->logical_maximum; |
| 771 | finfo.physical_minimum = field->physical_minimum; |
| 772 | finfo.physical_maximum = field->physical_maximum; |
| 773 | finfo.unit_exponent = field->unit_exponent; |
| 774 | finfo.unit = field->unit; |
| 775 | |
Valentine Barshak | 33d6eb5 | 2010-12-06 18:16:11 +0300 | [diff] [blame] | 776 | r = copy_to_user(user_arg, &finfo, sizeof(finfo)) ? |
| 777 | -EFAULT : 0; |
| 778 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | |
| 780 | case HIDIOCGUCODE: |
Jean Delvare | cf2a299 | 2008-03-03 11:48:43 +0100 | [diff] [blame] | 781 | /* fall through */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | case HIDIOCGUSAGE: |
| 783 | case HIDIOCSUSAGE: |
| 784 | case HIDIOCGUSAGES: |
| 785 | case HIDIOCSUSAGES: |
| 786 | case HIDIOCGCOLLECTIONINDEX: |
Valentine Barshak | 33d6eb5 | 2010-12-06 18:16:11 +0300 | [diff] [blame] | 787 | r = hiddev_ioctl_usage(hiddev, cmd, user_arg); |
| 788 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | |
| 790 | case HIDIOCGCOLLECTIONINFO: |
Valentine Barshak | 33d6eb5 | 2010-12-06 18:16:11 +0300 | [diff] [blame] | 791 | if (copy_from_user(&cinfo, user_arg, sizeof(cinfo))) { |
| 792 | r = -EFAULT; |
| 793 | break; |
Valentine Barshak | 1a8e8fa | 2010-12-06 17:51:41 +0300 | [diff] [blame] | 794 | } |
| 795 | |
Valentine Barshak | 33d6eb5 | 2010-12-06 18:16:11 +0300 | [diff] [blame] | 796 | if (cinfo.index >= hid->maxcollection) |
| 797 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | |
| 799 | cinfo.type = hid->collection[cinfo.index].type; |
| 800 | cinfo.usage = hid->collection[cinfo.index].usage; |
| 801 | cinfo.level = hid->collection[cinfo.index].level; |
| 802 | |
Valentine Barshak | 33d6eb5 | 2010-12-06 18:16:11 +0300 | [diff] [blame] | 803 | r = copy_to_user(user_arg, &cinfo, sizeof(cinfo)) ? |
| 804 | -EFAULT : 0; |
| 805 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | |
| 807 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | if (_IOC_TYPE(cmd) != 'H' || _IOC_DIR(cmd) != _IOC_READ) |
Valentine Barshak | 33d6eb5 | 2010-12-06 18:16:11 +0300 | [diff] [blame] | 809 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | |
| 811 | if (_IOC_NR(cmd) == _IOC_NR(HIDIOCGNAME(0))) { |
Daniel Mack | dd2ed48 | 2011-05-15 18:07:42 +0200 | [diff] [blame] | 812 | int len = strlen(hid->name) + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | if (len > _IOC_SIZE(cmd)) |
| 814 | len = _IOC_SIZE(cmd); |
Valentine Barshak | 1a8e8fa | 2010-12-06 17:51:41 +0300 | [diff] [blame] | 815 | r = copy_to_user(user_arg, hid->name, len) ? |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | -EFAULT : len; |
Valentine Barshak | 33d6eb5 | 2010-12-06 18:16:11 +0300 | [diff] [blame] | 817 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | } |
| 819 | |
| 820 | if (_IOC_NR(cmd) == _IOC_NR(HIDIOCGPHYS(0))) { |
Daniel Mack | dd2ed48 | 2011-05-15 18:07:42 +0200 | [diff] [blame] | 821 | int len = strlen(hid->phys) + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | if (len > _IOC_SIZE(cmd)) |
| 823 | len = _IOC_SIZE(cmd); |
Valentine Barshak | 1a8e8fa | 2010-12-06 17:51:41 +0300 | [diff] [blame] | 824 | r = copy_to_user(user_arg, hid->phys, len) ? |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | -EFAULT : len; |
Valentine Barshak | 33d6eb5 | 2010-12-06 18:16:11 +0300 | [diff] [blame] | 826 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | } |
| 828 | } |
Valentine Barshak | 33d6eb5 | 2010-12-06 18:16:11 +0300 | [diff] [blame] | 829 | |
| 830 | ret_unlock: |
| 831 | mutex_unlock(&hiddev->existancelock); |
| 832 | return r; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | } |
| 834 | |
Philip Langdale | bb6c8d8 | 2007-10-14 12:03:58 +0200 | [diff] [blame] | 835 | #ifdef CONFIG_COMPAT |
| 836 | static long hiddev_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
| 837 | { |
Jiri Kosina | 88af45b | 2008-05-27 11:36:40 +0200 | [diff] [blame] | 838 | return hiddev_ioctl(file, cmd, (unsigned long)compat_ptr(arg)); |
Philip Langdale | bb6c8d8 | 2007-10-14 12:03:58 +0200 | [diff] [blame] | 839 | } |
| 840 | #endif |
| 841 | |
Luiz Fernando N. Capitulino | 066202d | 2006-08-05 20:37:11 -0300 | [diff] [blame] | 842 | static const struct file_operations hiddev_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | .owner = THIS_MODULE, |
| 844 | .read = hiddev_read, |
| 845 | .write = hiddev_write, |
| 846 | .poll = hiddev_poll, |
| 847 | .open = hiddev_open, |
| 848 | .release = hiddev_release, |
Alan Cox | 7961df1 | 2008-05-26 11:25:20 +0200 | [diff] [blame] | 849 | .unlocked_ioctl = hiddev_ioctl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | .fasync = hiddev_fasync, |
Philip Langdale | bb6c8d8 | 2007-10-14 12:03:58 +0200 | [diff] [blame] | 851 | #ifdef CONFIG_COMPAT |
| 852 | .compat_ioctl = hiddev_compat_ioctl, |
| 853 | #endif |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 854 | .llseek = noop_llseek, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | }; |
| 856 | |
Kay Sievers | e454cea | 2009-09-18 23:01:12 +0200 | [diff] [blame] | 857 | static char *hiddev_devnode(struct device *dev, mode_t *mode) |
Kay Sievers | f7a386c | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 858 | { |
| 859 | return kasprintf(GFP_KERNEL, "usb/%s", dev_name(dev)); |
| 860 | } |
| 861 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | static struct usb_class_driver hiddev_class = { |
Greg Kroah-Hartman | d6e5bcf | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 863 | .name = "hiddev%d", |
Kay Sievers | e454cea | 2009-09-18 23:01:12 +0200 | [diff] [blame] | 864 | .devnode = hiddev_devnode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | .fops = &hiddev_fops, |
Dmitry Torokhov | 05f091a | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 866 | .minor_base = HIDDEV_MINOR_BASE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | }; |
| 868 | |
| 869 | /* |
| 870 | * This is where hid.c calls us to connect a hid device to the hiddev driver |
| 871 | */ |
Jiri Slaby | 93c1013 | 2008-06-27 00:04:24 +0200 | [diff] [blame] | 872 | int hiddev_connect(struct hid_device *hid, unsigned int force) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | { |
| 874 | struct hiddev *hiddev; |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 875 | struct usbhid_device *usbhid = hid->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | int retval; |
| 877 | |
Jiri Slaby | 93c1013 | 2008-06-27 00:04:24 +0200 | [diff] [blame] | 878 | if (!force) { |
| 879 | unsigned int i; |
| 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)) |
| 884 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | |
Jiri Slaby | 93c1013 | 2008-06-27 00:04:24 +0200 | [diff] [blame] | 886 | if (i == hid->maxcollection) |
| 887 | return -1; |
| 888 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | |
Oliver Neukum | bbdb7da | 2006-01-06 20:54:29 +0100 | [diff] [blame] | 890 | if (!(hiddev = kzalloc(sizeof(struct hiddev), GFP_KERNEL))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | |
Oliver Neukum | 0790340 | 2008-12-16 10:55:15 +0100 | [diff] [blame] | 893 | init_waitqueue_head(&hiddev->wait); |
| 894 | INIT_LIST_HEAD(&hiddev->list); |
| 895 | spin_lock_init(&hiddev->list_lock); |
| 896 | mutex_init(&hiddev->existancelock); |
Jiri Kosina | 7605274 | 2009-01-07 13:25:36 +0100 | [diff] [blame] | 897 | hid->hiddev = hiddev; |
Oliver Neukum | 0790340 | 2008-12-16 10:55:15 +0100 | [diff] [blame] | 898 | hiddev->hid = hid; |
| 899 | hiddev->exist = 1; |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 900 | retval = usb_register_dev(usbhid->intf, &hiddev_class); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | if (retval) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 902 | hid_err(hid, "Not able to get a minor for this device\n"); |
Jiri Kosina | 7605274 | 2009-01-07 13:25:36 +0100 | [diff] [blame] | 903 | hid->hiddev = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | kfree(hiddev); |
| 905 | return -1; |
| 906 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | return 0; |
| 908 | } |
| 909 | |
| 910 | /* |
| 911 | * This is where hid.c calls us to disconnect a hiddev device from the |
| 912 | * corresponding hid device (usually because the usb device has disconnected) |
| 913 | */ |
| 914 | static struct usb_class_driver hiddev_class; |
| 915 | void hiddev_disconnect(struct hid_device *hid) |
| 916 | { |
| 917 | struct hiddev *hiddev = hid->hiddev; |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 918 | struct usbhid_device *usbhid = hid->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | |
Oliver Neukum | 0790340 | 2008-12-16 10:55:15 +0100 | [diff] [blame] | 920 | mutex_lock(&hiddev->existancelock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | hiddev->exist = 0; |
| 922 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 923 | usb_deregister_dev(usbhid->intf, &hiddev_class); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | |
| 925 | if (hiddev->open) { |
Jiri Kosina | 7f77897 | 2011-05-24 11:43:18 +0200 | [diff] [blame] | 926 | mutex_unlock(&hiddev->existancelock); |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 927 | usbhid_close(hiddev->hid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 928 | wake_up_interruptible(&hiddev->wait); |
| 929 | } else { |
Jiri Kosina | 7f77897 | 2011-05-24 11:43:18 +0200 | [diff] [blame] | 930 | mutex_unlock(&hiddev->existancelock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 931 | kfree(hiddev); |
| 932 | } |
| 933 | } |