diff options
-rw-r--r-- | drivers/usb/usb-skeleton.c | 43 |
1 files changed, 28 insertions, 15 deletions
diff --git a/drivers/usb/usb-skeleton.c b/drivers/usb/usb-skeleton.c index ef8c877cdd41..b62f2bc064f6 100644 --- a/drivers/usb/usb-skeleton.c +++ b/drivers/usb/usb-skeleton.c | |||
@@ -18,7 +18,7 @@ | |||
18 | #include <linux/slab.h> | 18 | #include <linux/slab.h> |
19 | #include <linux/module.h> | 19 | #include <linux/module.h> |
20 | #include <linux/kref.h> | 20 | #include <linux/kref.h> |
21 | #include <asm/uaccess.h> | 21 | #include <linux/uaccess.h> |
22 | #include <linux/usb.h> | 22 | #include <linux/usb.h> |
23 | #include <linux/mutex.h> | 23 | #include <linux/mutex.h> |
24 | 24 | ||
@@ -28,7 +28,7 @@ | |||
28 | #define USB_SKEL_PRODUCT_ID 0xfff0 | 28 | #define USB_SKEL_PRODUCT_ID 0xfff0 |
29 | 29 | ||
30 | /* table of devices that work with this driver */ | 30 | /* table of devices that work with this driver */ |
31 | static struct usb_device_id skel_table [] = { | 31 | static struct usb_device_id skel_table[] = { |
32 | { USB_DEVICE(USB_SKEL_VENDOR_ID, USB_SKEL_PRODUCT_ID) }, | 32 | { USB_DEVICE(USB_SKEL_VENDOR_ID, USB_SKEL_PRODUCT_ID) }, |
33 | { } /* Terminating entry */ | 33 | { } /* Terminating entry */ |
34 | }; | 34 | }; |
@@ -94,7 +94,7 @@ static int skel_open(struct inode *inode, struct file *file) | |||
94 | 94 | ||
95 | interface = usb_find_interface(&skel_driver, subminor); | 95 | interface = usb_find_interface(&skel_driver, subminor); |
96 | if (!interface) { | 96 | if (!interface) { |
97 | err ("%s - error, can't find device for minor %d", | 97 | err("%s - error, can't find device for minor %d", |
98 | __func__, subminor); | 98 | __func__, subminor); |
99 | retval = -ENODEV; | 99 | retval = -ENODEV; |
100 | goto exit; | 100 | goto exit; |
@@ -190,7 +190,7 @@ static void skel_read_bulk_callback(struct urb *urb) | |||
190 | spin_lock(&dev->err_lock); | 190 | spin_lock(&dev->err_lock); |
191 | /* sync/async unlink faults aren't errors */ | 191 | /* sync/async unlink faults aren't errors */ |
192 | if (urb->status) { | 192 | if (urb->status) { |
193 | if(!(urb->status == -ENOENT || | 193 | if (!(urb->status == -ENOENT || |
194 | urb->status == -ECONNRESET || | 194 | urb->status == -ECONNRESET || |
195 | urb->status == -ESHUTDOWN)) | 195 | urb->status == -ESHUTDOWN)) |
196 | err("%s - nonzero write bulk status received: %d", | 196 | err("%s - nonzero write bulk status received: %d", |
@@ -239,7 +239,8 @@ static int skel_do_read_io(struct usb_skel *dev, size_t count) | |||
239 | return rv; | 239 | return rv; |
240 | } | 240 | } |
241 | 241 | ||
242 | static ssize_t skel_read(struct file *file, char *buffer, size_t count, loff_t *ppos) | 242 | static ssize_t skel_read(struct file *file, char *buffer, size_t count, |
243 | loff_t *ppos) | ||
243 | { | 244 | { |
244 | struct usb_skel *dev; | 245 | struct usb_skel *dev; |
245 | int rv; | 246 | int rv; |
@@ -299,7 +300,8 @@ retry: | |||
299 | } | 300 | } |
300 | 301 | ||
301 | /* errors must be reported */ | 302 | /* errors must be reported */ |
302 | if ((rv = dev->errors) < 0) { | 303 | rv = dev->errors; |
304 | if (rv < 0) { | ||
303 | /* any error is reported once */ | 305 | /* any error is reported once */ |
304 | dev->errors = 0; | 306 | dev->errors = 0; |
305 | /* to preserve notifications about reset */ | 307 | /* to preserve notifications about reset */ |
@@ -373,7 +375,7 @@ static void skel_write_bulk_callback(struct urb *urb) | |||
373 | 375 | ||
374 | /* sync/async unlink faults aren't errors */ | 376 | /* sync/async unlink faults aren't errors */ |
375 | if (urb->status) { | 377 | if (urb->status) { |
376 | if(!(urb->status == -ENOENT || | 378 | if (!(urb->status == -ENOENT || |
377 | urb->status == -ECONNRESET || | 379 | urb->status == -ECONNRESET || |
378 | urb->status == -ESHUTDOWN)) | 380 | urb->status == -ESHUTDOWN)) |
379 | err("%s - nonzero write bulk status received: %d", | 381 | err("%s - nonzero write bulk status received: %d", |
@@ -390,7 +392,8 @@ static void skel_write_bulk_callback(struct urb *urb) | |||
390 | up(&dev->limit_sem); | 392 | up(&dev->limit_sem); |
391 | } | 393 | } |
392 | 394 | ||
393 | static ssize_t skel_write(struct file *file, const char *user_buffer, size_t count, loff_t *ppos) | 395 | static ssize_t skel_write(struct file *file, const char *user_buffer, |
396 | size_t count, loff_t *ppos) | ||
394 | { | 397 | { |
395 | struct usb_skel *dev; | 398 | struct usb_skel *dev; |
396 | int retval = 0; | 399 | int retval = 0; |
@@ -404,7 +407,10 @@ static ssize_t skel_write(struct file *file, const char *user_buffer, size_t cou | |||
404 | if (count == 0) | 407 | if (count == 0) |
405 | goto exit; | 408 | goto exit; |
406 | 409 | ||
407 | /* limit the number of URBs in flight to stop a user from using up all RAM */ | 410 | /* |
411 | * limit the number of URBs in flight to stop a user from using up all | ||
412 | * RAM | ||
413 | */ | ||
408 | if (!file->f_flags & O_NONBLOCK) { | 414 | if (!file->f_flags & O_NONBLOCK) { |
409 | if (down_interruptible(&dev->limit_sem)) { | 415 | if (down_interruptible(&dev->limit_sem)) { |
410 | retval = -ERESTARTSYS; | 416 | retval = -ERESTARTSYS; |
@@ -418,7 +424,8 @@ static ssize_t skel_write(struct file *file, const char *user_buffer, size_t cou | |||
418 | } | 424 | } |
419 | 425 | ||
420 | spin_lock_irq(&dev->err_lock); | 426 | spin_lock_irq(&dev->err_lock); |
421 | if ((retval = dev->errors) < 0) { | 427 | retval = dev->errors; |
428 | if (retval < 0) { | ||
422 | /* any error is reported once */ | 429 | /* any error is reported once */ |
423 | dev->errors = 0; | 430 | dev->errors = 0; |
424 | /* to preserve notifications about reset */ | 431 | /* to preserve notifications about reset */ |
@@ -435,7 +442,8 @@ static ssize_t skel_write(struct file *file, const char *user_buffer, size_t cou | |||
435 | goto error; | 442 | goto error; |
436 | } | 443 | } |
437 | 444 | ||
438 | buf = usb_buffer_alloc(dev->udev, writesize, GFP_KERNEL, &urb->transfer_dma); | 445 | buf = usb_buffer_alloc(dev->udev, writesize, GFP_KERNEL, |
446 | &urb->transfer_dma); | ||
439 | if (!buf) { | 447 | if (!buf) { |
440 | retval = -ENOMEM; | 448 | retval = -ENOMEM; |
441 | goto error; | 449 | goto error; |
@@ -465,11 +473,15 @@ static ssize_t skel_write(struct file *file, const char *user_buffer, size_t cou | |||
465 | retval = usb_submit_urb(urb, GFP_KERNEL); | 473 | retval = usb_submit_urb(urb, GFP_KERNEL); |
466 | mutex_unlock(&dev->io_mutex); | 474 | mutex_unlock(&dev->io_mutex); |
467 | if (retval) { | 475 | if (retval) { |
468 | err("%s - failed submitting write urb, error %d", __func__, retval); | 476 | err("%s - failed submitting write urb, error %d", __func__, |
477 | retval); | ||
469 | goto error_unanchor; | 478 | goto error_unanchor; |
470 | } | 479 | } |
471 | 480 | ||
472 | /* release our reference to this urb, the USB core will eventually free it entirely */ | 481 | /* |
482 | * release our reference to this urb, the USB core will eventually free | ||
483 | * it entirely | ||
484 | */ | ||
473 | usb_free_urb(urb); | 485 | usb_free_urb(urb); |
474 | 486 | ||
475 | 487 | ||
@@ -507,7 +519,8 @@ static struct usb_class_driver skel_class = { | |||
507 | .minor_base = USB_SKEL_MINOR_BASE, | 519 | .minor_base = USB_SKEL_MINOR_BASE, |
508 | }; | 520 | }; |
509 | 521 | ||
510 | static int skel_probe(struct usb_interface *interface, const struct usb_device_id *id) | 522 | static int skel_probe(struct usb_interface *interface, |
523 | const struct usb_device_id *id) | ||
511 | { | 524 | { |
512 | struct usb_skel *dev; | 525 | struct usb_skel *dev; |
513 | struct usb_host_interface *iface_desc; | 526 | struct usb_host_interface *iface_desc; |
@@ -636,7 +649,7 @@ static int skel_suspend(struct usb_interface *intf, pm_message_t message) | |||
636 | return 0; | 649 | return 0; |
637 | } | 650 | } |
638 | 651 | ||
639 | static int skel_resume (struct usb_interface *intf) | 652 | static int skel_resume(struct usb_interface *intf) |
640 | { | 653 | { |
641 | return 0; | 654 | return 0; |
642 | } | 655 | } |