usb-skeleton.c 17 KB

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