hidraw.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * HID raw devices, giving access to raw HID events.
  4. *
  5. * In comparison to hiddev, this device does not process the
  6. * hid events at all (no parsing, no lookups). This lets applications
  7. * to work on raw hid events as they want to, and avoids a need to
  8. * use a transport-specific userspace libhid/libusb libraries.
  9. *
  10. * Copyright (c) 2007-2014 Jiri Kosina
  11. */
  12. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  13. #include <linux/fs.h>
  14. #include <linux/module.h>
  15. #include <linux/errno.h>
  16. #include <linux/kernel.h>
  17. #include <linux/init.h>
  18. #include <linux/cdev.h>
  19. #include <linux/poll.h>
  20. #include <linux/device.h>
  21. #include <linux/major.h>
  22. #include <linux/slab.h>
  23. #include <linux/hid.h>
  24. #include <linux/mutex.h>
  25. #include <linux/sched/signal.h>
  26. #include <linux/string.h>
  27. #include <linux/hidraw.h>
  28. static int hidraw_major;
  29. static struct cdev hidraw_cdev;
  30. static const struct class hidraw_class = {
  31. .name = "hidraw",
  32. };
  33. static struct hidraw *hidraw_table[HIDRAW_MAX_DEVICES];
  34. static DECLARE_RWSEM(minors_rwsem);
  35. static inline bool hidraw_is_revoked(struct hidraw_list *list)
  36. {
  37. return list->revoked;
  38. }
  39. static ssize_t hidraw_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
  40. {
  41. struct hidraw_list *list = file->private_data;
  42. int ret = 0, len;
  43. DECLARE_WAITQUEUE(wait, current);
  44. if (hidraw_is_revoked(list))
  45. return -ENODEV;
  46. mutex_lock(&list->read_mutex);
  47. while (ret == 0) {
  48. if (list->head == list->tail) {
  49. add_wait_queue(&list->hidraw->wait, &wait);
  50. set_current_state(TASK_INTERRUPTIBLE);
  51. while (list->head == list->tail) {
  52. if (signal_pending(current)) {
  53. ret = -ERESTARTSYS;
  54. break;
  55. }
  56. if (!list->hidraw->exist) {
  57. ret = -EIO;
  58. break;
  59. }
  60. if (file->f_flags & O_NONBLOCK) {
  61. ret = -EAGAIN;
  62. break;
  63. }
  64. /* allow O_NONBLOCK to work well from other threads */
  65. mutex_unlock(&list->read_mutex);
  66. schedule();
  67. mutex_lock(&list->read_mutex);
  68. set_current_state(TASK_INTERRUPTIBLE);
  69. }
  70. set_current_state(TASK_RUNNING);
  71. remove_wait_queue(&list->hidraw->wait, &wait);
  72. }
  73. if (ret)
  74. goto out;
  75. len = list->buffer[list->tail].len > count ?
  76. count : list->buffer[list->tail].len;
  77. if (list->buffer[list->tail].value) {
  78. if (copy_to_user(buffer, list->buffer[list->tail].value, len)) {
  79. ret = -EFAULT;
  80. goto out;
  81. }
  82. ret = len;
  83. }
  84. kfree(list->buffer[list->tail].value);
  85. list->buffer[list->tail].value = NULL;
  86. list->tail = (list->tail + 1) & (HIDRAW_BUFFER_SIZE - 1);
  87. }
  88. out:
  89. mutex_unlock(&list->read_mutex);
  90. return ret;
  91. }
  92. /*
  93. * The first byte of the report buffer is expected to be a report number.
  94. */
  95. static ssize_t hidraw_send_report(struct file *file, const char __user *buffer, size_t count, unsigned char report_type)
  96. {
  97. unsigned int minor = iminor(file_inode(file));
  98. struct hid_device *dev;
  99. __u8 *buf;
  100. int ret = 0;
  101. lockdep_assert_held(&minors_rwsem);
  102. if (!hidraw_table[minor] || !hidraw_table[minor]->exist) {
  103. ret = -ENODEV;
  104. goto out;
  105. }
  106. dev = hidraw_table[minor]->hid;
  107. if (count > HID_MAX_BUFFER_SIZE) {
  108. hid_warn(dev, "pid %d passed too large report\n",
  109. task_pid_nr(current));
  110. ret = -EINVAL;
  111. goto out;
  112. }
  113. if (count < 2) {
  114. hid_warn(dev, "pid %d passed too short report\n",
  115. task_pid_nr(current));
  116. ret = -EINVAL;
  117. goto out;
  118. }
  119. buf = memdup_user(buffer, count);
  120. if (IS_ERR(buf)) {
  121. ret = PTR_ERR(buf);
  122. goto out;
  123. }
  124. if ((report_type == HID_OUTPUT_REPORT) &&
  125. !(dev->quirks & HID_QUIRK_NO_OUTPUT_REPORTS_ON_INTR_EP)) {
  126. ret = __hid_hw_output_report(dev, buf, count, (u64)(long)file, false);
  127. /*
  128. * compatibility with old implementation of USB-HID and I2C-HID:
  129. * if the device does not support receiving output reports,
  130. * on an interrupt endpoint, fallback to SET_REPORT HID command.
  131. */
  132. if (ret != -ENOSYS)
  133. goto out_free;
  134. }
  135. ret = __hid_hw_raw_request(dev, buf[0], buf, count, report_type,
  136. HID_REQ_SET_REPORT, (u64)(long)file, false);
  137. out_free:
  138. kfree(buf);
  139. out:
  140. return ret;
  141. }
  142. static ssize_t hidraw_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos)
  143. {
  144. struct hidraw_list *list = file->private_data;
  145. ssize_t ret;
  146. down_read(&minors_rwsem);
  147. if (hidraw_is_revoked(list))
  148. ret = -ENODEV;
  149. else
  150. ret = hidraw_send_report(file, buffer, count, HID_OUTPUT_REPORT);
  151. up_read(&minors_rwsem);
  152. return ret;
  153. }
  154. /*
  155. * This function performs a Get_Report transfer over the control endpoint
  156. * per section 7.2.1 of the HID specification, version 1.1. The first byte
  157. * of buffer is the report number to request, or 0x0 if the device does not
  158. * use numbered reports. The report_type parameter can be HID_FEATURE_REPORT
  159. * or HID_INPUT_REPORT.
  160. */
  161. static ssize_t hidraw_get_report(struct file *file, char __user *buffer, size_t count, unsigned char report_type)
  162. {
  163. unsigned int minor = iminor(file_inode(file));
  164. struct hid_device *dev;
  165. __u8 *buf;
  166. int ret = 0, len;
  167. unsigned char report_number;
  168. lockdep_assert_held(&minors_rwsem);
  169. if (!hidraw_table[minor] || !hidraw_table[minor]->exist) {
  170. ret = -ENODEV;
  171. goto out;
  172. }
  173. dev = hidraw_table[minor]->hid;
  174. if (!dev->ll_driver->raw_request) {
  175. ret = -ENODEV;
  176. goto out;
  177. }
  178. if (count > HID_MAX_BUFFER_SIZE) {
  179. hid_warn(dev, "pid %d passed too large report\n",
  180. task_pid_nr(current));
  181. ret = -EINVAL;
  182. goto out;
  183. }
  184. if (count < 2) {
  185. hid_warn(dev, "pid %d passed too short report\n",
  186. task_pid_nr(current));
  187. ret = -EINVAL;
  188. goto out;
  189. }
  190. buf = kmalloc(count, GFP_KERNEL);
  191. if (!buf) {
  192. ret = -ENOMEM;
  193. goto out;
  194. }
  195. /*
  196. * Read the first byte from the user. This is the report number,
  197. * which is passed to hid_hw_raw_request().
  198. */
  199. if (copy_from_user(&report_number, buffer, 1)) {
  200. ret = -EFAULT;
  201. goto out_free;
  202. }
  203. ret = __hid_hw_raw_request(dev, report_number, buf, count, report_type,
  204. HID_REQ_GET_REPORT, (u64)(long)file, false);
  205. if (ret < 0)
  206. goto out_free;
  207. len = (ret < count) ? ret : count;
  208. if (copy_to_user(buffer, buf, len)) {
  209. ret = -EFAULT;
  210. goto out_free;
  211. }
  212. ret = len;
  213. out_free:
  214. kfree(buf);
  215. out:
  216. return ret;
  217. }
  218. static __poll_t hidraw_poll(struct file *file, poll_table *wait)
  219. {
  220. struct hidraw_list *list = file->private_data;
  221. __poll_t mask = EPOLLOUT | EPOLLWRNORM; /* hidraw is always writable */
  222. poll_wait(file, &list->hidraw->wait, wait);
  223. if (list->head != list->tail)
  224. mask |= EPOLLIN | EPOLLRDNORM;
  225. if (!list->hidraw->exist || hidraw_is_revoked(list))
  226. mask |= EPOLLERR | EPOLLHUP;
  227. return mask;
  228. }
  229. static int hidraw_open(struct inode *inode, struct file *file)
  230. {
  231. unsigned int minor = iminor(inode);
  232. struct hidraw *dev;
  233. struct hidraw_list *list;
  234. unsigned long flags;
  235. int err = 0;
  236. if (!(list = kzalloc(sizeof(struct hidraw_list), GFP_KERNEL))) {
  237. err = -ENOMEM;
  238. goto out;
  239. }
  240. /*
  241. * Technically not writing to the hidraw_table but a write lock is
  242. * required to protect the device refcount. This is symmetrical to
  243. * hidraw_release().
  244. */
  245. down_write(&minors_rwsem);
  246. if (!hidraw_table[minor] || !hidraw_table[minor]->exist) {
  247. err = -ENODEV;
  248. goto out_unlock;
  249. }
  250. dev = hidraw_table[minor];
  251. if (!dev->open++) {
  252. err = hid_hw_power(dev->hid, PM_HINT_FULLON);
  253. if (err < 0) {
  254. dev->open--;
  255. goto out_unlock;
  256. }
  257. err = hid_hw_open(dev->hid);
  258. if (err < 0) {
  259. hid_hw_power(dev->hid, PM_HINT_NORMAL);
  260. dev->open--;
  261. goto out_unlock;
  262. }
  263. }
  264. list->hidraw = hidraw_table[minor];
  265. mutex_init(&list->read_mutex);
  266. spin_lock_irqsave(&hidraw_table[minor]->list_lock, flags);
  267. list_add_tail(&list->node, &hidraw_table[minor]->list);
  268. spin_unlock_irqrestore(&hidraw_table[minor]->list_lock, flags);
  269. file->private_data = list;
  270. out_unlock:
  271. up_write(&minors_rwsem);
  272. out:
  273. if (err < 0)
  274. kfree(list);
  275. return err;
  276. }
  277. static int hidraw_fasync(int fd, struct file *file, int on)
  278. {
  279. struct hidraw_list *list = file->private_data;
  280. if (hidraw_is_revoked(list))
  281. return -ENODEV;
  282. return fasync_helper(fd, file, on, &list->fasync);
  283. }
  284. static void drop_ref(struct hidraw *hidraw, int exists_bit)
  285. {
  286. if (exists_bit) {
  287. hidraw->exist = 0;
  288. if (hidraw->open) {
  289. hid_hw_close(hidraw->hid);
  290. wake_up_interruptible(&hidraw->wait);
  291. }
  292. device_destroy(&hidraw_class,
  293. MKDEV(hidraw_major, hidraw->minor));
  294. } else {
  295. --hidraw->open;
  296. }
  297. if (!hidraw->open) {
  298. if (!hidraw->exist) {
  299. hidraw_table[hidraw->minor] = NULL;
  300. kfree(hidraw);
  301. } else {
  302. /* close device for last reader */
  303. hid_hw_close(hidraw->hid);
  304. hid_hw_power(hidraw->hid, PM_HINT_NORMAL);
  305. }
  306. }
  307. }
  308. static int hidraw_release(struct inode * inode, struct file * file)
  309. {
  310. unsigned int minor = iminor(inode);
  311. struct hidraw_list *list = file->private_data;
  312. unsigned long flags;
  313. down_write(&minors_rwsem);
  314. spin_lock_irqsave(&hidraw_table[minor]->list_lock, flags);
  315. while (list->tail != list->head) {
  316. kfree(list->buffer[list->tail].value);
  317. list->buffer[list->tail].value = NULL;
  318. list->tail = (list->tail + 1) & (HIDRAW_BUFFER_SIZE - 1);
  319. }
  320. list_del(&list->node);
  321. spin_unlock_irqrestore(&hidraw_table[minor]->list_lock, flags);
  322. kfree(list);
  323. drop_ref(hidraw_table[minor], 0);
  324. up_write(&minors_rwsem);
  325. return 0;
  326. }
  327. static int hidraw_revoke(struct hidraw_list *list)
  328. {
  329. list->revoked = true;
  330. return 0;
  331. }
  332. static long hidraw_fixed_size_ioctl(struct file *file, struct hidraw *dev, unsigned int cmd,
  333. void __user *arg)
  334. {
  335. struct hid_device *hid = dev->hid;
  336. switch (cmd) {
  337. case HIDIOCGRDESCSIZE:
  338. if (put_user(hid->rsize, (int __user *)arg))
  339. return -EFAULT;
  340. break;
  341. case HIDIOCGRDESC:
  342. {
  343. __u32 len;
  344. if (get_user(len, (int __user *)arg))
  345. return -EFAULT;
  346. if (len > HID_MAX_DESCRIPTOR_SIZE - 1)
  347. return -EINVAL;
  348. if (copy_to_user(arg + offsetof(
  349. struct hidraw_report_descriptor,
  350. value[0]),
  351. hid->rdesc,
  352. min(hid->rsize, len)))
  353. return -EFAULT;
  354. break;
  355. }
  356. case HIDIOCGRAWINFO:
  357. {
  358. struct hidraw_devinfo dinfo;
  359. dinfo.bustype = hid->bus;
  360. dinfo.vendor = hid->vendor;
  361. dinfo.product = hid->product;
  362. if (copy_to_user(arg, &dinfo, sizeof(dinfo)))
  363. return -EFAULT;
  364. break;
  365. }
  366. case HIDIOCREVOKE:
  367. {
  368. struct hidraw_list *list = file->private_data;
  369. if (arg)
  370. return -EINVAL;
  371. return hidraw_revoke(list);
  372. }
  373. default:
  374. /*
  375. * None of the above ioctls can return -EAGAIN, so
  376. * use it as a marker that we need to check variable
  377. * length ioctls.
  378. */
  379. return -EAGAIN;
  380. }
  381. return 0;
  382. }
  383. static long hidraw_rw_variable_size_ioctl(struct file *file, struct hidraw *dev, unsigned int cmd,
  384. void __user *user_arg)
  385. {
  386. int len = _IOC_SIZE(cmd);
  387. switch (cmd & ~IOCSIZE_MASK) {
  388. case HIDIOCSFEATURE(0):
  389. return hidraw_send_report(file, user_arg, len, HID_FEATURE_REPORT);
  390. case HIDIOCGFEATURE(0):
  391. return hidraw_get_report(file, user_arg, len, HID_FEATURE_REPORT);
  392. case HIDIOCSINPUT(0):
  393. return hidraw_send_report(file, user_arg, len, HID_INPUT_REPORT);
  394. case HIDIOCGINPUT(0):
  395. return hidraw_get_report(file, user_arg, len, HID_INPUT_REPORT);
  396. case HIDIOCSOUTPUT(0):
  397. return hidraw_send_report(file, user_arg, len, HID_OUTPUT_REPORT);
  398. case HIDIOCGOUTPUT(0):
  399. return hidraw_get_report(file, user_arg, len, HID_OUTPUT_REPORT);
  400. }
  401. return -EINVAL;
  402. }
  403. static long hidraw_ro_variable_size_ioctl(struct file *file, struct hidraw *dev, unsigned int cmd,
  404. void __user *user_arg)
  405. {
  406. struct hid_device *hid = dev->hid;
  407. int len = _IOC_SIZE(cmd);
  408. int field_len;
  409. switch (cmd & ~IOCSIZE_MASK) {
  410. case HIDIOCGRAWNAME(0):
  411. field_len = strlen(hid->name) + 1;
  412. if (len > field_len)
  413. len = field_len;
  414. return copy_to_user(user_arg, hid->name, len) ? -EFAULT : len;
  415. case HIDIOCGRAWPHYS(0):
  416. field_len = strlen(hid->phys) + 1;
  417. if (len > field_len)
  418. len = field_len;
  419. return copy_to_user(user_arg, hid->phys, len) ? -EFAULT : len;
  420. case HIDIOCGRAWUNIQ(0):
  421. field_len = strlen(hid->uniq) + 1;
  422. if (len > field_len)
  423. len = field_len;
  424. return copy_to_user(user_arg, hid->uniq, len) ? -EFAULT : len;
  425. }
  426. return -EINVAL;
  427. }
  428. static long hidraw_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  429. {
  430. struct inode *inode = file_inode(file);
  431. unsigned int minor = iminor(inode);
  432. struct hidraw *dev;
  433. struct hidraw_list *list = file->private_data;
  434. void __user *user_arg = (void __user *)arg;
  435. int ret;
  436. down_read(&minors_rwsem);
  437. dev = hidraw_table[minor];
  438. if (!dev || !dev->exist || hidraw_is_revoked(list)) {
  439. ret = -ENODEV;
  440. goto out;
  441. }
  442. if (_IOC_TYPE(cmd) != 'H') {
  443. ret = -EINVAL;
  444. goto out;
  445. }
  446. if (_IOC_NR(cmd) > HIDIOCTL_LAST || _IOC_NR(cmd) == 0) {
  447. ret = -ENOTTY;
  448. goto out;
  449. }
  450. ret = hidraw_fixed_size_ioctl(file, dev, cmd, user_arg);
  451. if (ret != -EAGAIN)
  452. goto out;
  453. switch (_IOC_DIR(cmd)) {
  454. case (_IOC_READ | _IOC_WRITE):
  455. ret = hidraw_rw_variable_size_ioctl(file, dev, cmd, user_arg);
  456. break;
  457. case _IOC_READ:
  458. ret = hidraw_ro_variable_size_ioctl(file, dev, cmd, user_arg);
  459. break;
  460. default:
  461. /* Any other IOC_DIR is wrong */
  462. ret = -EINVAL;
  463. }
  464. out:
  465. up_read(&minors_rwsem);
  466. return ret;
  467. }
  468. static const struct file_operations hidraw_ops = {
  469. .owner = THIS_MODULE,
  470. .read = hidraw_read,
  471. .write = hidraw_write,
  472. .poll = hidraw_poll,
  473. .open = hidraw_open,
  474. .release = hidraw_release,
  475. .unlocked_ioctl = hidraw_ioctl,
  476. .fasync = hidraw_fasync,
  477. .compat_ioctl = compat_ptr_ioctl,
  478. .llseek = noop_llseek,
  479. };
  480. int hidraw_report_event(struct hid_device *hid, u8 *data, int len)
  481. {
  482. struct hidraw *dev = hid->hidraw;
  483. struct hidraw_list *list;
  484. int ret = 0;
  485. unsigned long flags;
  486. spin_lock_irqsave(&dev->list_lock, flags);
  487. list_for_each_entry(list, &dev->list, node) {
  488. int new_head = (list->head + 1) & (HIDRAW_BUFFER_SIZE - 1);
  489. if (hidraw_is_revoked(list) || new_head == list->tail)
  490. continue;
  491. if (!(list->buffer[list->head].value = kmemdup(data, len, GFP_ATOMIC))) {
  492. ret = -ENOMEM;
  493. break;
  494. }
  495. list->buffer[list->head].len = len;
  496. list->head = new_head;
  497. kill_fasync(&list->fasync, SIGIO, POLL_IN);
  498. }
  499. spin_unlock_irqrestore(&dev->list_lock, flags);
  500. wake_up_interruptible(&dev->wait);
  501. return ret;
  502. }
  503. EXPORT_SYMBOL_GPL(hidraw_report_event);
  504. int hidraw_connect(struct hid_device *hid)
  505. {
  506. int minor, result;
  507. struct hidraw *dev;
  508. /* we accept any HID device, all applications */
  509. dev = kzalloc(sizeof(struct hidraw), GFP_KERNEL);
  510. if (!dev)
  511. return -ENOMEM;
  512. result = -EINVAL;
  513. down_write(&minors_rwsem);
  514. for (minor = 0; minor < HIDRAW_MAX_DEVICES; minor++) {
  515. if (hidraw_table[minor])
  516. continue;
  517. hidraw_table[minor] = dev;
  518. result = 0;
  519. break;
  520. }
  521. if (result) {
  522. up_write(&minors_rwsem);
  523. kfree(dev);
  524. goto out;
  525. }
  526. dev->dev = device_create(&hidraw_class, &hid->dev, MKDEV(hidraw_major, minor),
  527. NULL, "%s%d", "hidraw", minor);
  528. if (IS_ERR(dev->dev)) {
  529. hidraw_table[minor] = NULL;
  530. up_write(&minors_rwsem);
  531. result = PTR_ERR(dev->dev);
  532. kfree(dev);
  533. goto out;
  534. }
  535. init_waitqueue_head(&dev->wait);
  536. spin_lock_init(&dev->list_lock);
  537. INIT_LIST_HEAD(&dev->list);
  538. dev->hid = hid;
  539. dev->minor = minor;
  540. dev->exist = 1;
  541. hid->hidraw = dev;
  542. up_write(&minors_rwsem);
  543. out:
  544. return result;
  545. }
  546. EXPORT_SYMBOL_GPL(hidraw_connect);
  547. void hidraw_disconnect(struct hid_device *hid)
  548. {
  549. struct hidraw *hidraw = hid->hidraw;
  550. down_write(&minors_rwsem);
  551. drop_ref(hidraw, 1);
  552. up_write(&minors_rwsem);
  553. }
  554. EXPORT_SYMBOL_GPL(hidraw_disconnect);
  555. int __init hidraw_init(void)
  556. {
  557. int result;
  558. dev_t dev_id;
  559. result = alloc_chrdev_region(&dev_id, HIDRAW_FIRST_MINOR,
  560. HIDRAW_MAX_DEVICES, "hidraw");
  561. if (result < 0) {
  562. pr_warn("can't get major number\n");
  563. goto out;
  564. }
  565. hidraw_major = MAJOR(dev_id);
  566. result = class_register(&hidraw_class);
  567. if (result)
  568. goto error_cdev;
  569. cdev_init(&hidraw_cdev, &hidraw_ops);
  570. result = cdev_add(&hidraw_cdev, dev_id, HIDRAW_MAX_DEVICES);
  571. if (result < 0)
  572. goto error_class;
  573. pr_info("raw HID events driver (C) Jiri Kosina\n");
  574. out:
  575. return result;
  576. error_class:
  577. class_unregister(&hidraw_class);
  578. error_cdev:
  579. unregister_chrdev_region(dev_id, HIDRAW_MAX_DEVICES);
  580. goto out;
  581. }
  582. void hidraw_exit(void)
  583. {
  584. dev_t dev_id = MKDEV(hidraw_major, 0);
  585. cdev_del(&hidraw_cdev);
  586. class_unregister(&hidraw_class);
  587. unregister_chrdev_region(dev_id, HIDRAW_MAX_DEVICES);
  588. }