usb-skeleton.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  1. /*
  2. * USB Skeleton driver - 2.2
  3. *
  4. * Copyright (C) 2001-2004 Greg Kroah-Hartman (greg@kroah.com)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation, version 2.
  9. *
  10. * This driver is based on the 2.6.3 version of drivers/usb/usb-skeleton.c
  11. * but has been rewritten to be easier to read and use.
  12. *
  13. */
  14. #include <linux/kernel.h>
  15. #include <linux/errno.h>
  16. #include <linux/init.h>
  17. #include <linux/slab.h>
  18. #include <linux/module.h>
  19. #include <linux/kref.h>
  20. #include <linux/uaccess.h>
  21. #include <linux/usb.h>
  22. #include <linux/mutex.h>
  23. /* Define these values to match your devices */
  24. #define USB_SKEL_VENDOR_ID 0xfff0
  25. #define USB_SKEL_PRODUCT_ID 0xfff0
  26. /* table of devices that work with this driver */
  27. static const struct usb_device_id skel_table[] = {
  28. { USB_DEVICE(USB_SKEL_VENDOR_ID, USB_SKEL_PRODUCT_ID) },
  29. { } /* Terminating entry */
  30. };
  31. MODULE_DEVICE_TABLE(usb, skel_table);
  32. /* Get a minor range for your devices from the usb maintainer */
  33. #define USB_SKEL_MINOR_BASE 192
  34. /* our private defines. if this grows any larger, use your own .h file */
  35. #define MAX_TRANSFER (PAGE_SIZE - 512)
  36. /* MAX_TRANSFER is chosen so that the VM is not stressed by
  37. allocations > PAGE_SIZE and the number of packets in a page
  38. is an integer 512 is the largest possible packet on EHCI */
  39. #define WRITES_IN_FLIGHT 8
  40. /* arbitrarily chosen */
  41. /* Structure to hold all of our device specific stuff */
  42. struct usb_skel {
  43. struct usb_device *udev; /* the usb device for this device */
  44. struct usb_interface *interface; /* the interface for this device */
  45. struct semaphore limit_sem; /* limiting the number of writes in progress */
  46. struct usb_anchor submitted; /* in case we need to retract our submissions */
  47. struct urb *bulk_in_urb; /* the urb to read data with */
  48. unsigned char *bulk_in_buffer; /* the buffer to receive data */
  49. size_t bulk_in_size; /* the size of the receive buffer */
  50. size_t bulk_in_filled; /* number of bytes in the buffer */
  51. size_t bulk_in_copied; /* already copied to user space */
  52. __u8 bulk_in_endpointAddr; /* the address of the bulk in endpoint */
  53. __u8 bulk_out_endpointAddr; /* the address of the bulk out endpoint */
  54. int errors; /* the last request tanked */
  55. int open_count; /* count the number of openers */
  56. bool ongoing_read; /* a read is going on */
  57. bool processed_urb; /* indicates we haven't processed the urb */
  58. spinlock_t err_lock; /* lock for errors */
  59. struct kref kref;
  60. struct mutex io_mutex; /* synchronize I/O with disconnect */
  61. struct completion bulk_in_completion; /* to wait for an ongoing read */
  62. };
  63. #define to_skel_dev(d) container_of(d, struct usb_skel, kref)
  64. static struct usb_driver skel_driver;
  65. static void skel_draw_down(struct usb_skel *dev);
  66. static void skel_delete(struct kref *kref)
  67. {
  68. struct usb_skel *dev = to_skel_dev(kref);
  69. usb_free_urb(dev->bulk_in_urb);
  70. usb_put_dev(dev->udev);
  71. kfree(dev->bulk_in_buffer);
  72. kfree(dev);
  73. }
  74. static int skel_open(struct inode *inode, struct file *file)
  75. {
  76. struct usb_skel *dev;
  77. struct usb_interface *interface;
  78. int subminor;
  79. int retval = 0;
  80. subminor = iminor(inode);
  81. interface = usb_find_interface(&skel_driver, subminor);
  82. if (!interface) {
  83. err("%s - error, can't find device for minor %d",
  84. __func__, subminor);
  85. retval = -ENODEV;
  86. goto exit;
  87. }
  88. dev = usb_get_intfdata(interface);
  89. if (!dev) {
  90. retval = -ENODEV;
  91. goto exit;
  92. }
  93. /* increment our usage count for the device */
  94. kref_get(&dev->kref);
  95. /* lock the device to allow correctly handling errors
  96. * in resumption */
  97. mutex_lock(&dev->io_mutex);
  98. if (!dev->open_count++) {
  99. retval = usb_autopm_get_interface(interface);
  100. if (retval) {
  101. dev->open_count--;
  102. mutex_unlock(&dev->io_mutex);
  103. kref_put(&dev->kref, skel_delete);
  104. goto exit;
  105. }
  106. } /* else { //uncomment this block if you want exclusive open
  107. retval = -EBUSY;
  108. dev->open_count--;
  109. mutex_unlock(&dev->io_mutex);
  110. kref_put(&dev->kref, skel_delete);
  111. goto exit;
  112. } */
  113. /* prevent the device from being autosuspended */
  114. /* save our object in the file's private structure */
  115. file->private_data = dev;
  116. mutex_unlock(&dev->io_mutex);
  117. exit:
  118. return retval;
  119. }
  120. static int skel_release(struct inode *inode, struct file *file)
  121. {
  122. struct usb_skel *dev;
  123. dev = file->private_data;
  124. if (dev == NULL)
  125. return -ENODEV;
  126. /* allow the device to be autosuspended */
  127. mutex_lock(&dev->io_mutex);
  128. if (!--dev->open_count && dev->interface)
  129. usb_autopm_put_interface(dev->interface);
  130. mutex_unlock(&dev->io_mutex);
  131. /* decrement the count on our device */
  132. kref_put(&dev->kref, skel_delete);
  133. return 0;
  134. }
  135. static int skel_flush(struct file *file, fl_owner_t id)
  136. {
  137. struct usb_skel *dev;
  138. int res;
  139. dev = file->private_data;
  140. if (dev == NULL)
  141. return -ENODEV;
  142. /* wait for io to stop */
  143. mutex_lock(&dev->io_mutex);
  144. skel_draw_down(dev);
  145. /* read out errors, leave subsequent opens a clean slate */
  146. spin_lock_irq(&dev->err_lock);
  147. res = dev->errors ? (dev->errors == -EPIPE ? -EPIPE : -EIO) : 0;
  148. dev->errors = 0;
  149. spin_unlock_irq(&dev->err_lock);
  150. mutex_unlock(&dev->io_mutex);
  151. return res;
  152. }
  153. static void skel_read_bulk_callback(struct urb *urb)
  154. {
  155. struct usb_skel *dev;
  156. dev = urb->context;
  157. spin_lock(&dev->err_lock);
  158. /* sync/async unlink faults aren't errors */
  159. if (urb->status) {
  160. if (!(urb->status == -ENOENT ||
  161. urb->status == -ECONNRESET ||
  162. urb->status == -ESHUTDOWN))
  163. err("%s - nonzero write bulk status received: %d",
  164. __func__, urb->status);
  165. dev->errors = urb->status;
  166. } else {
  167. dev->bulk_in_filled = urb->actual_length;
  168. }
  169. dev->ongoing_read = 0;
  170. spin_unlock(&dev->err_lock);
  171. complete(&dev->bulk_in_completion);
  172. }
  173. static int skel_do_read_io(struct usb_skel *dev, size_t count)
  174. {
  175. int rv;
  176. /* prepare a read */
  177. usb_fill_bulk_urb(dev->bulk_in_urb,
  178. dev->udev,
  179. usb_rcvbulkpipe(dev->udev,
  180. dev->bulk_in_endpointAddr),
  181. dev->bulk_in_buffer,
  182. min(dev->bulk_in_size, count),
  183. skel_read_bulk_callback,
  184. dev);
  185. /* tell everybody to leave the URB alone */
  186. spin_lock_irq(&dev->err_lock);
  187. dev->ongoing_read = 1;
  188. spin_unlock_irq(&dev->err_lock);
  189. /* do it */
  190. rv = usb_submit_urb(dev->bulk_in_urb, GFP_KERNEL);
  191. if (rv < 0) {
  192. err("%s - failed submitting read urb, error %d",
  193. __func__, rv);
  194. dev->bulk_in_filled = 0;
  195. rv = (rv == -ENOMEM) ? rv : -EIO;
  196. spin_lock_irq(&dev->err_lock);
  197. dev->ongoing_read = 0;
  198. spin_unlock_irq(&dev->err_lock);
  199. }
  200. return rv;
  201. }
  202. static ssize_t skel_read(struct file *file, char *buffer, size_t count,
  203. loff_t *ppos)
  204. {
  205. struct usb_skel *dev;
  206. int rv;
  207. bool ongoing_io;
  208. dev = file->private_data;
  209. /* if we cannot read at all, return EOF */
  210. if (!dev->bulk_in_urb || !count)
  211. return 0;
  212. /* no concurrent readers */
  213. rv = mutex_lock_interruptible(&dev->io_mutex);
  214. if (rv < 0)
  215. return rv;
  216. if (!dev->interface) { /* disconnect() was called */
  217. rv = -ENODEV;
  218. goto exit;
  219. }
  220. /* if IO is under way, we must not touch things */
  221. retry:
  222. spin_lock_irq(&dev->err_lock);
  223. ongoing_io = dev->ongoing_read;
  224. spin_unlock_irq(&dev->err_lock);
  225. if (ongoing_io) {
  226. /* nonblocking IO shall not wait */
  227. if (file->f_flags & O_NONBLOCK) {
  228. rv = -EAGAIN;
  229. goto exit;
  230. }
  231. /*
  232. * IO may take forever
  233. * hence wait in an interruptible state
  234. */
  235. rv = wait_for_completion_interruptible(&dev->bulk_in_completion);
  236. if (rv < 0)
  237. goto exit;
  238. /*
  239. * by waiting we also semiprocessed the urb
  240. * we must finish now
  241. */
  242. dev->bulk_in_copied = 0;
  243. dev->processed_urb = 1;
  244. }
  245. if (!dev->processed_urb) {
  246. /*
  247. * the URB hasn't been processed
  248. * do it now
  249. */
  250. wait_for_completion(&dev->bulk_in_completion);
  251. dev->bulk_in_copied = 0;
  252. dev->processed_urb = 1;
  253. }
  254. /* errors must be reported */
  255. rv = dev->errors;
  256. if (rv < 0) {
  257. /* any error is reported once */
  258. dev->errors = 0;
  259. /* to preserve notifications about reset */
  260. rv = (rv == -EPIPE) ? rv : -EIO;
  261. /* no data to deliver */
  262. dev->bulk_in_filled = 0;
  263. /* report it */
  264. goto exit;
  265. }
  266. /*
  267. * if the buffer is filled we may satisfy the read
  268. * else we need to start IO
  269. */
  270. if (dev->bulk_in_filled) {
  271. /* we had read data */
  272. size_t available = dev->bulk_in_filled - dev->bulk_in_copied;
  273. size_t chunk = min(available, count);
  274. if (!available) {
  275. /*
  276. * all data has been used
  277. * actual IO needs to be done
  278. */
  279. rv = skel_do_read_io(dev, count);
  280. if (rv < 0)
  281. goto exit;
  282. else
  283. goto retry;
  284. }
  285. /*
  286. * data is available
  287. * chunk tells us how much shall be copied
  288. */
  289. if (copy_to_user(buffer,
  290. dev->bulk_in_buffer + dev->bulk_in_copied,
  291. chunk))
  292. rv = -EFAULT;
  293. else
  294. rv = chunk;
  295. dev->bulk_in_copied += chunk;
  296. /*
  297. * if we are asked for more than we have,
  298. * we start IO but don't wait
  299. */
  300. if (available < count)
  301. skel_do_read_io(dev, count - chunk);
  302. } else {
  303. /* no data in the buffer */
  304. rv = skel_do_read_io(dev, count);
  305. if (rv < 0)
  306. goto exit;
  307. else if (!(file->f_flags & O_NONBLOCK))
  308. goto retry;
  309. rv = -EAGAIN;
  310. }
  311. exit:
  312. mutex_unlock(&dev->io_mutex);
  313. return rv;
  314. }
  315. static void skel_write_bulk_callback(struct urb *urb)
  316. {
  317. struct usb_skel *dev;
  318. dev = urb->context;
  319. /* sync/async unlink faults aren't errors */
  320. if (urb->status) {
  321. if (!(urb->status == -ENOENT ||
  322. urb->status == -ECONNRESET ||
  323. urb->status == -ESHUTDOWN))
  324. err("%s - nonzero write bulk status received: %d",
  325. __func__, urb->status);
  326. spin_lock(&dev->err_lock);
  327. dev->errors = urb->status;
  328. spin_unlock(&dev->err_lock);
  329. }
  330. /* free up our allocated buffer */
  331. usb_free_coherent(urb->dev, urb->transfer_buffer_length,
  332. urb->transfer_buffer, urb->transfer_dma);
  333. up(&dev->limit_sem);
  334. }
  335. static ssize_t skel_write(struct file *file, const char *user_buffer,
  336. size_t count, loff_t *ppos)
  337. {
  338. struct usb_skel *dev;
  339. int retval = 0;
  340. struct urb *urb = NULL;
  341. char *buf = NULL;
  342. size_t writesize = min(count, (size_t)MAX_TRANSFER);
  343. dev = file->private_data;
  344. /* verify that we actually have some data to write */
  345. if (count == 0)
  346. goto exit;
  347. /*
  348. * limit the number of URBs in flight to stop a user from using up all
  349. * RAM
  350. */
  351. if (!(file->f_flags & O_NONBLOCK)) {
  352. if (down_interruptible(&dev->limit_sem)) {
  353. retval = -ERESTARTSYS;
  354. goto exit;
  355. }
  356. } else {
  357. if (down_trylock(&dev->limit_sem)) {
  358. retval = -EAGAIN;
  359. goto exit;
  360. }
  361. }
  362. spin_lock_irq(&dev->err_lock);
  363. retval = dev->errors;
  364. if (retval < 0) {
  365. /* any error is reported once */
  366. dev->errors = 0;
  367. /* to preserve notifications about reset */
  368. retval = (retval == -EPIPE) ? retval : -EIO;
  369. }
  370. spin_unlock_irq(&dev->err_lock);
  371. if (retval < 0)
  372. goto error;
  373. /* create a urb, and a buffer for it, and copy the data to the urb */
  374. urb = usb_alloc_urb(0, GFP_KERNEL);
  375. if (!urb) {
  376. retval = -ENOMEM;
  377. goto error;
  378. }
  379. buf = usb_alloc_coherent(dev->udev, writesize, GFP_KERNEL,
  380. &urb->transfer_dma);
  381. if (!buf) {
  382. retval = -ENOMEM;
  383. goto error;
  384. }
  385. if (copy_from_user(buf, user_buffer, writesize)) {
  386. retval = -EFAULT;
  387. goto error;
  388. }
  389. /* this lock makes sure we don't submit URBs to gone devices */
  390. mutex_lock(&dev->io_mutex);
  391. if (!dev->interface) { /* disconnect() was called */
  392. mutex_unlock(&dev->io_mutex);
  393. retval = -ENODEV;
  394. goto error;
  395. }
  396. /* initialize the urb properly */
  397. usb_fill_bulk_urb(urb, dev->udev,
  398. usb_sndbulkpipe(dev->udev, dev->bulk_out_endpointAddr),
  399. buf, writesize, skel_write_bulk_callback, dev);
  400. urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
  401. usb_anchor_urb(urb, &dev->submitted);
  402. /* send the data out the bulk port */
  403. retval = usb_submit_urb(urb, GFP_KERNEL);
  404. mutex_unlock(&dev->io_mutex);
  405. if (retval) {
  406. err("%s - failed submitting write urb, error %d", __func__,
  407. retval);
  408. goto error_unanchor;
  409. }
  410. /*
  411. * release our reference to this urb, the USB core will eventually free
  412. * it entirely
  413. */
  414. usb_free_urb(urb);
  415. return writesize;
  416. error_unanchor:
  417. usb_unanchor_urb(urb);
  418. error:
  419. if (urb) {
  420. usb_free_coherent(dev->udev, writesize, buf, urb->transfer_dma);
  421. usb_free_urb(urb);
  422. }
  423. up(&dev->limit_sem);
  424. exit:
  425. return retval;
  426. }
  427. static const struct file_operations skel_fops = {
  428. .owner = THIS_MODULE,
  429. .read = skel_read,
  430. .write = skel_write,
  431. .open = skel_open,
  432. .release = skel_release,
  433. .flush = skel_flush,
  434. .llseek = noop_llseek,
  435. };
  436. /*
  437. * usb class driver info in order to get a minor number from the usb core,
  438. * and to have the device registered with the driver core
  439. */
  440. static struct usb_class_driver skel_class = {
  441. .name = "skel%d",
  442. .fops = &skel_fops,
  443. .minor_base = USB_SKEL_MINOR_BASE,
  444. };
  445. static int skel_probe(struct usb_interface *interface,
  446. const struct usb_device_id *id)
  447. {
  448. struct usb_skel *dev;
  449. struct usb_host_interface *iface_desc;
  450. struct usb_endpoint_descriptor *endpoint;
  451. size_t buffer_size;
  452. int i;
  453. int retval = -ENOMEM;
  454. /* allocate memory for our device state and initialize it */
  455. dev = kzalloc(sizeof(*dev), GFP_KERNEL);
  456. if (!dev) {
  457. err("Out of memory");
  458. goto error;
  459. }
  460. kref_init(&dev->kref);
  461. sema_init(&dev->limit_sem, WRITES_IN_FLIGHT);
  462. mutex_init(&dev->io_mutex);
  463. spin_lock_init(&dev->err_lock);
  464. init_usb_anchor(&dev->submitted);
  465. init_completion(&dev->bulk_in_completion);
  466. dev->udev = usb_get_dev(interface_to_usbdev(interface));
  467. dev->interface = interface;
  468. /* set up the endpoint information */
  469. /* use only the first bulk-in and bulk-out endpoints */
  470. iface_desc = interface->cur_altsetting;
  471. for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
  472. endpoint = &iface_desc->endpoint[i].desc;
  473. if (!dev->bulk_in_endpointAddr &&
  474. usb_endpoint_is_bulk_in(endpoint)) {
  475. /* we found a bulk in endpoint */
  476. buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
  477. dev->bulk_in_size = buffer_size;
  478. dev->bulk_in_endpointAddr = endpoint->bEndpointAddress;
  479. dev->bulk_in_buffer = kmalloc(buffer_size, GFP_KERNEL);
  480. if (!dev->bulk_in_buffer) {
  481. err("Could not allocate bulk_in_buffer");
  482. goto error;
  483. }
  484. dev->bulk_in_urb = usb_alloc_urb(0, GFP_KERNEL);
  485. if (!dev->bulk_in_urb) {
  486. err("Could not allocate bulk_in_urb");
  487. goto error;
  488. }
  489. }
  490. if (!dev->bulk_out_endpointAddr &&
  491. usb_endpoint_is_bulk_out(endpoint)) {
  492. /* we found a bulk out endpoint */
  493. dev->bulk_out_endpointAddr = endpoint->bEndpointAddress;
  494. }
  495. }
  496. if (!(dev->bulk_in_endpointAddr && dev->bulk_out_endpointAddr)) {
  497. err("Could not find both bulk-in and bulk-out endpoints");
  498. goto error;
  499. }
  500. /* save our data pointer in this interface device */
  501. usb_set_intfdata(interface, dev);
  502. /* we can register the device now, as it is ready */
  503. retval = usb_register_dev(interface, &skel_class);
  504. if (retval) {
  505. /* something prevented us from registering this driver */
  506. err("Not able to get a minor for this device.");
  507. usb_set_intfdata(interface, NULL);
  508. goto error;
  509. }
  510. /* let the user know what node this device is now attached to */
  511. dev_info(&interface->dev,
  512. "USB Skeleton device now attached to USBSkel-%d",
  513. interface->minor);
  514. return 0;
  515. error:
  516. if (dev)
  517. /* this frees allocated memory */
  518. kref_put(&dev->kref, skel_delete);
  519. return retval;
  520. }
  521. static void skel_disconnect(struct usb_interface *interface)
  522. {
  523. struct usb_skel *dev;
  524. int minor = interface->minor;
  525. dev = usb_get_intfdata(interface);
  526. usb_set_intfdata(interface, NULL);
  527. /* give back our minor */
  528. usb_deregister_dev(interface, &skel_class);
  529. /* prevent more I/O from starting */
  530. mutex_lock(&dev->io_mutex);
  531. dev->interface = NULL;
  532. mutex_unlock(&dev->io_mutex);
  533. usb_kill_anchored_urbs(&dev->submitted);
  534. /* decrement our usage count */
  535. kref_put(&dev->kref, skel_delete);
  536. dev_info(&interface->dev, "USB Skeleton #%d now disconnected", minor);
  537. }
  538. static void skel_draw_down(struct usb_skel *dev)
  539. {
  540. int time;
  541. time = usb_wait_anchor_empty_timeout(&dev->submitted, 1000);
  542. if (!time)
  543. usb_kill_anchored_urbs(&dev->submitted);
  544. usb_kill_urb(dev->bulk_in_urb);
  545. }
  546. static int skel_suspend(struct usb_interface *intf, pm_message_t message)
  547. {
  548. struct usb_skel *dev = usb_get_intfdata(intf);
  549. if (!dev)
  550. return 0;
  551. skel_draw_down(dev);
  552. return 0;
  553. }
  554. static int skel_resume(struct usb_interface *intf)
  555. {
  556. return 0;
  557. }
  558. static int skel_pre_reset(struct usb_interface *intf)
  559. {
  560. struct usb_skel *dev = usb_get_intfdata(intf);
  561. mutex_lock(&dev->io_mutex);
  562. skel_draw_down(dev);
  563. return 0;
  564. }
  565. static int skel_post_reset(struct usb_interface *intf)
  566. {
  567. struct usb_skel *dev = usb_get_intfdata(intf);
  568. /* we are sure no URBs are active - no locking needed */
  569. dev->errors = -EPIPE;
  570. mutex_unlock(&dev->io_mutex);
  571. return 0;
  572. }
  573. static struct usb_driver skel_driver = {
  574. .name = "skeleton",
  575. .probe = skel_probe,
  576. .disconnect = skel_disconnect,
  577. .suspend = skel_suspend,
  578. .resume = skel_resume,
  579. .pre_reset = skel_pre_reset,
  580. .post_reset = skel_post_reset,
  581. .id_table = skel_table,
  582. .supports_autosuspend = 1,
  583. };
  584. static int __init usb_skel_init(void)
  585. {
  586. int result;
  587. /* register this driver with the USB subsystem */
  588. result = usb_register(&skel_driver);
  589. if (result)
  590. err("usb_register failed. Error number %d", result);
  591. return result;
  592. }
  593. static void __exit usb_skel_exit(void)
  594. {
  595. /* deregister this driver with the USB subsystem */
  596. usb_deregister(&skel_driver);
  597. }
  598. module_init(usb_skel_init);
  599. module_exit(usb_skel_exit);
  600. MODULE_LICENSE("GPL");