diff options
author | Michal Nazarewicz <mina86@mina86.com> | 2010-10-28 11:31:23 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2010-11-11 08:58:49 -0500 |
commit | b73af61e3283068f680e58e091ceafcb88d74b22 (patch) | |
tree | 8fec72d260053e26179413e2e2ec6b434800ce99 /drivers/usb/gadget | |
parent | 00cb636ed87a65b512012ea4236348af19daef1e (diff) |
USB: gadget: f_mass_storage: code style clean ups
This commit is purely style clean ups.
Signed-off-by: Michal Nazarewicz <mina86@mina86.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/gadget')
-rw-r--r-- | drivers/usb/gadget/f_mass_storage.c | 458 | ||||
-rw-r--r-- | drivers/usb/gadget/mass_storage.c | 2 |
2 files changed, 249 insertions, 211 deletions
diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c index 365f1b3ab155..b5dbb2308f56 100644 --- a/drivers/usb/gadget/f_mass_storage.c +++ b/drivers/usb/gadget/f_mass_storage.c | |||
@@ -37,7 +37,6 @@ | |||
37 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 37 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
38 | */ | 38 | */ |
39 | 39 | ||
40 | |||
41 | /* | 40 | /* |
42 | * The Mass Storage Function acts as a USB Mass Storage device, | 41 | * The Mass Storage Function acts as a USB Mass Storage device, |
43 | * appearing to the host as a disk drive or as a CD-ROM drive. In | 42 | * appearing to the host as a disk drive or as a CD-ROM drive. In |
@@ -185,7 +184,6 @@ | |||
185 | * <http://www.usb.org/developers/devclass_docs/usbmass-ufi10.pdf>. | 184 | * <http://www.usb.org/developers/devclass_docs/usbmass-ufi10.pdf>. |
186 | */ | 185 | */ |
187 | 186 | ||
188 | |||
189 | /* | 187 | /* |
190 | * Driver Design | 188 | * Driver Design |
191 | * | 189 | * |
@@ -275,7 +273,6 @@ | |||
275 | /* #define VERBOSE_DEBUG */ | 273 | /* #define VERBOSE_DEBUG */ |
276 | /* #define DUMP_MSGS */ | 274 | /* #define DUMP_MSGS */ |
277 | 275 | ||
278 | |||
279 | #include <linux/blkdev.h> | 276 | #include <linux/blkdev.h> |
280 | #include <linux/completion.h> | 277 | #include <linux/completion.h> |
281 | #include <linux/dcache.h> | 278 | #include <linux/dcache.h> |
@@ -300,7 +297,6 @@ | |||
300 | #include "gadget_chips.h" | 297 | #include "gadget_chips.h" |
301 | 298 | ||
302 | 299 | ||
303 | |||
304 | /*------------------------------------------------------------------------*/ | 300 | /*------------------------------------------------------------------------*/ |
305 | 301 | ||
306 | #define FSG_DRIVER_DESC "Mass Storage Function" | 302 | #define FSG_DRIVER_DESC "Mass Storage Function" |
@@ -308,7 +304,6 @@ | |||
308 | 304 | ||
309 | static const char fsg_string_interface[] = "Mass Storage"; | 305 | static const char fsg_string_interface[] = "Mass Storage"; |
310 | 306 | ||
311 | |||
312 | #define FSG_NO_INTR_EP 1 | 307 | #define FSG_NO_INTR_EP 1 |
313 | #define FSG_NO_DEVICE_STRINGS 1 | 308 | #define FSG_NO_DEVICE_STRINGS 1 |
314 | #define FSG_NO_OTG 1 | 309 | #define FSG_NO_OTG 1 |
@@ -324,25 +319,30 @@ struct fsg_common; | |||
324 | 319 | ||
325 | /* FSF callback functions */ | 320 | /* FSF callback functions */ |
326 | struct fsg_operations { | 321 | struct fsg_operations { |
327 | /* Callback function to call when thread exits. If no | 322 | /* |
323 | * Callback function to call when thread exits. If no | ||
328 | * callback is set or it returns value lower then zero MSF | 324 | * callback is set or it returns value lower then zero MSF |
329 | * will force eject all LUNs it operates on (including those | 325 | * will force eject all LUNs it operates on (including those |
330 | * marked as non-removable or with prevent_medium_removal flag | 326 | * marked as non-removable or with prevent_medium_removal flag |
331 | * set). */ | 327 | * set). |
328 | */ | ||
332 | int (*thread_exits)(struct fsg_common *common); | 329 | int (*thread_exits)(struct fsg_common *common); |
333 | 330 | ||
334 | /* Called prior to ejection. Negative return means error, | 331 | /* |
332 | * Called prior to ejection. Negative return means error, | ||
335 | * zero means to continue with ejection, positive means not to | 333 | * zero means to continue with ejection, positive means not to |
336 | * eject. */ | 334 | * eject. |
335 | */ | ||
337 | int (*pre_eject)(struct fsg_common *common, | 336 | int (*pre_eject)(struct fsg_common *common, |
338 | struct fsg_lun *lun, int num); | 337 | struct fsg_lun *lun, int num); |
339 | /* Called after ejection. Negative return means error, zero | 338 | /* |
340 | * or positive is just a success. */ | 339 | * Called after ejection. Negative return means error, zero |
340 | * or positive is just a success. | ||
341 | */ | ||
341 | int (*post_eject)(struct fsg_common *common, | 342 | int (*post_eject)(struct fsg_common *common, |
342 | struct fsg_lun *lun, int num); | 343 | struct fsg_lun *lun, int num); |
343 | }; | 344 | }; |
344 | 345 | ||
345 | |||
346 | /* Data shared by all the FSG instances. */ | 346 | /* Data shared by all the FSG instances. */ |
347 | struct fsg_common { | 347 | struct fsg_common { |
348 | struct usb_gadget *gadget; | 348 | struct usb_gadget *gadget; |
@@ -398,14 +398,15 @@ struct fsg_common { | |||
398 | /* Gadget's private data. */ | 398 | /* Gadget's private data. */ |
399 | void *private_data; | 399 | void *private_data; |
400 | 400 | ||
401 | /* Vendor (8 chars), product (16 chars), release (4 | 401 | /* |
402 | * hexadecimal digits) and NUL byte */ | 402 | * Vendor (8 chars), product (16 chars), release (4 |
403 | * hexadecimal digits) and NUL byte | ||
404 | */ | ||
403 | char inquiry_string[8 + 16 + 4 + 1]; | 405 | char inquiry_string[8 + 16 + 4 + 1]; |
404 | 406 | ||
405 | struct kref ref; | 407 | struct kref ref; |
406 | }; | 408 | }; |
407 | 409 | ||
408 | |||
409 | struct fsg_config { | 410 | struct fsg_config { |
410 | unsigned nluns; | 411 | unsigned nluns; |
411 | struct fsg_lun_config { | 412 | struct fsg_lun_config { |
@@ -431,7 +432,6 @@ struct fsg_config { | |||
431 | char can_stall; | 432 | char can_stall; |
432 | }; | 433 | }; |
433 | 434 | ||
434 | |||
435 | struct fsg_dev { | 435 | struct fsg_dev { |
436 | struct usb_function function; | 436 | struct usb_function function; |
437 | struct usb_gadget *gadget; /* Copy of cdev->gadget */ | 437 | struct usb_gadget *gadget; /* Copy of cdev->gadget */ |
@@ -449,7 +449,6 @@ struct fsg_dev { | |||
449 | struct usb_ep *bulk_out; | 449 | struct usb_ep *bulk_out; |
450 | }; | 450 | }; |
451 | 451 | ||
452 | |||
453 | static inline int __fsg_is_set(struct fsg_common *common, | 452 | static inline int __fsg_is_set(struct fsg_common *common, |
454 | const char *func, unsigned line) | 453 | const char *func, unsigned line) |
455 | { | 454 | { |
@@ -462,13 +461,11 @@ static inline int __fsg_is_set(struct fsg_common *common, | |||
462 | 461 | ||
463 | #define fsg_is_set(common) likely(__fsg_is_set(common, __func__, __LINE__)) | 462 | #define fsg_is_set(common) likely(__fsg_is_set(common, __func__, __LINE__)) |
464 | 463 | ||
465 | |||
466 | static inline struct fsg_dev *fsg_from_func(struct usb_function *f) | 464 | static inline struct fsg_dev *fsg_from_func(struct usb_function *f) |
467 | { | 465 | { |
468 | return container_of(f, struct fsg_dev, function); | 466 | return container_of(f, struct fsg_dev, function); |
469 | } | 467 | } |
470 | 468 | ||
471 | |||
472 | typedef void (*fsg_routine_t)(struct fsg_dev *); | 469 | typedef void (*fsg_routine_t)(struct fsg_dev *); |
473 | 470 | ||
474 | static int exception_in_progress(struct fsg_common *common) | 471 | static int exception_in_progress(struct fsg_common *common) |
@@ -478,7 +475,7 @@ static int exception_in_progress(struct fsg_common *common) | |||
478 | 475 | ||
479 | /* Make bulk-out requests be divisible by the maxpacket size */ | 476 | /* Make bulk-out requests be divisible by the maxpacket size */ |
480 | static void set_bulk_out_req_length(struct fsg_common *common, | 477 | static void set_bulk_out_req_length(struct fsg_common *common, |
481 | struct fsg_buffhd *bh, unsigned int length) | 478 | struct fsg_buffhd *bh, unsigned int length) |
482 | { | 479 | { |
483 | unsigned int rem; | 480 | unsigned int rem; |
484 | 481 | ||
@@ -489,6 +486,7 @@ static void set_bulk_out_req_length(struct fsg_common *common, | |||
489 | bh->outreq->length = length; | 486 | bh->outreq->length = length; |
490 | } | 487 | } |
491 | 488 | ||
489 | |||
492 | /*-------------------------------------------------------------------------*/ | 490 | /*-------------------------------------------------------------------------*/ |
493 | 491 | ||
494 | static int fsg_set_halt(struct fsg_dev *fsg, struct usb_ep *ep) | 492 | static int fsg_set_halt(struct fsg_dev *fsg, struct usb_ep *ep) |
@@ -519,14 +517,15 @@ static void wakeup_thread(struct fsg_common *common) | |||
519 | wake_up_process(common->thread_task); | 517 | wake_up_process(common->thread_task); |
520 | } | 518 | } |
521 | 519 | ||
522 | |||
523 | static void raise_exception(struct fsg_common *common, enum fsg_state new_state) | 520 | static void raise_exception(struct fsg_common *common, enum fsg_state new_state) |
524 | { | 521 | { |
525 | unsigned long flags; | 522 | unsigned long flags; |
526 | 523 | ||
527 | /* Do nothing if a higher-priority exception is already in progress. | 524 | /* |
525 | * Do nothing if a higher-priority exception is already in progress. | ||
528 | * If a lower-or-equal priority exception is in progress, preempt it | 526 | * If a lower-or-equal priority exception is in progress, preempt it |
529 | * and notify the main thread by sending it a signal. */ | 527 | * and notify the main thread by sending it a signal. |
528 | */ | ||
530 | spin_lock_irqsave(&common->lock, flags); | 529 | spin_lock_irqsave(&common->lock, flags); |
531 | if (common->state <= new_state) { | 530 | if (common->state <= new_state) { |
532 | common->exception_req_tag = common->ep0_req_tag; | 531 | common->exception_req_tag = common->ep0_req_tag; |
@@ -555,10 +554,10 @@ static int ep0_queue(struct fsg_common *common) | |||
555 | return rc; | 554 | return rc; |
556 | } | 555 | } |
557 | 556 | ||
557 | |||
558 | /*-------------------------------------------------------------------------*/ | 558 | /*-------------------------------------------------------------------------*/ |
559 | 559 | ||
560 | /* Bulk and interrupt endpoint completion handlers. | 560 | /* Completion handlers. These always run in_irq. */ |
561 | * These always run in_irq. */ | ||
562 | 561 | ||
563 | static void bulk_in_complete(struct usb_ep *ep, struct usb_request *req) | 562 | static void bulk_in_complete(struct usb_ep *ep, struct usb_request *req) |
564 | { | 563 | { |
@@ -567,7 +566,7 @@ static void bulk_in_complete(struct usb_ep *ep, struct usb_request *req) | |||
567 | 566 | ||
568 | if (req->status || req->actual != req->length) | 567 | if (req->status || req->actual != req->length) |
569 | DBG(common, "%s --> %d, %u/%u\n", __func__, | 568 | DBG(common, "%s --> %d, %u/%u\n", __func__, |
570 | req->status, req->actual, req->length); | 569 | req->status, req->actual, req->length); |
571 | if (req->status == -ECONNRESET) /* Request was cancelled */ | 570 | if (req->status == -ECONNRESET) /* Request was cancelled */ |
572 | usb_ep_fifo_flush(ep); | 571 | usb_ep_fifo_flush(ep); |
573 | 572 | ||
@@ -588,8 +587,7 @@ static void bulk_out_complete(struct usb_ep *ep, struct usb_request *req) | |||
588 | dump_msg(common, "bulk-out", req->buf, req->actual); | 587 | dump_msg(common, "bulk-out", req->buf, req->actual); |
589 | if (req->status || req->actual != bh->bulk_out_intended_length) | 588 | if (req->status || req->actual != bh->bulk_out_intended_length) |
590 | DBG(common, "%s --> %d, %u/%u\n", __func__, | 589 | DBG(common, "%s --> %d, %u/%u\n", __func__, |
591 | req->status, req->actual, | 590 | req->status, req->actual, bh->bulk_out_intended_length); |
592 | bh->bulk_out_intended_length); | ||
593 | if (req->status == -ECONNRESET) /* Request was cancelled */ | 591 | if (req->status == -ECONNRESET) /* Request was cancelled */ |
594 | usb_ep_fifo_flush(ep); | 592 | usb_ep_fifo_flush(ep); |
595 | 593 | ||
@@ -602,13 +600,8 @@ static void bulk_out_complete(struct usb_ep *ep, struct usb_request *req) | |||
602 | spin_unlock(&common->lock); | 600 | spin_unlock(&common->lock); |
603 | } | 601 | } |
604 | 602 | ||
605 | |||
606 | /*-------------------------------------------------------------------------*/ | ||
607 | |||
608 | /* Ep0 class-specific handlers. These always run in_irq. */ | ||
609 | |||
610 | static int fsg_setup(struct usb_function *f, | 603 | static int fsg_setup(struct usb_function *f, |
611 | const struct usb_ctrlrequest *ctrl) | 604 | const struct usb_ctrlrequest *ctrl) |
612 | { | 605 | { |
613 | struct fsg_dev *fsg = fsg_from_func(f); | 606 | struct fsg_dev *fsg = fsg_from_func(f); |
614 | struct usb_request *req = fsg->common->ep0req; | 607 | struct usb_request *req = fsg->common->ep0req; |
@@ -628,8 +621,10 @@ static int fsg_setup(struct usb_function *f, | |||
628 | if (w_index != fsg->interface_number || w_value != 0) | 621 | if (w_index != fsg->interface_number || w_value != 0) |
629 | return -EDOM; | 622 | return -EDOM; |
630 | 623 | ||
631 | /* Raise an exception to stop the current operation | 624 | /* |
632 | * and reinitialize our state. */ | 625 | * Raise an exception to stop the current operation |
626 | * and reinitialize our state. | ||
627 | */ | ||
633 | DBG(fsg, "bulk reset request\n"); | 628 | DBG(fsg, "bulk reset request\n"); |
634 | raise_exception(fsg->common, FSG_STATE_RESET); | 629 | raise_exception(fsg->common, FSG_STATE_RESET); |
635 | return DELAYED_STATUS; | 630 | return DELAYED_STATUS; |
@@ -641,7 +636,7 @@ static int fsg_setup(struct usb_function *f, | |||
641 | if (w_index != fsg->interface_number || w_value != 0) | 636 | if (w_index != fsg->interface_number || w_value != 0) |
642 | return -EDOM; | 637 | return -EDOM; |
643 | VDBG(fsg, "get max LUN\n"); | 638 | VDBG(fsg, "get max LUN\n"); |
644 | *(u8 *) req->buf = fsg->common->nluns - 1; | 639 | *(u8 *)req->buf = fsg->common->nluns - 1; |
645 | 640 | ||
646 | /* Respond with data/status */ | 641 | /* Respond with data/status */ |
647 | req->length = min((u16)1, w_length); | 642 | req->length = min((u16)1, w_length); |
@@ -649,8 +644,7 @@ static int fsg_setup(struct usb_function *f, | |||
649 | } | 644 | } |
650 | 645 | ||
651 | VDBG(fsg, | 646 | VDBG(fsg, |
652 | "unknown class-specific control req " | 647 | "unknown class-specific control req %02x.%02x v%04x i%04x l%u\n", |
653 | "%02x.%02x v%04x i%04x l%u\n", | ||
654 | ctrl->bRequestType, ctrl->bRequest, | 648 | ctrl->bRequestType, ctrl->bRequest, |
655 | le16_to_cpu(ctrl->wValue), w_index, w_length); | 649 | le16_to_cpu(ctrl->wValue), w_index, w_length); |
656 | return -EOPNOTSUPP; | 650 | return -EOPNOTSUPP; |
@@ -661,11 +655,10 @@ static int fsg_setup(struct usb_function *f, | |||
661 | 655 | ||
662 | /* All the following routines run in process context */ | 656 | /* All the following routines run in process context */ |
663 | 657 | ||
664 | |||
665 | /* Use this for bulk or interrupt transfers, not ep0 */ | 658 | /* Use this for bulk or interrupt transfers, not ep0 */ |
666 | static void start_transfer(struct fsg_dev *fsg, struct usb_ep *ep, | 659 | static void start_transfer(struct fsg_dev *fsg, struct usb_ep *ep, |
667 | struct usb_request *req, int *pbusy, | 660 | struct usb_request *req, int *pbusy, |
668 | enum fsg_buffer_state *state) | 661 | enum fsg_buffer_state *state) |
669 | { | 662 | { |
670 | int rc; | 663 | int rc; |
671 | 664 | ||
@@ -683,12 +676,14 @@ static void start_transfer(struct fsg_dev *fsg, struct usb_ep *ep, | |||
683 | 676 | ||
684 | /* We can't do much more than wait for a reset */ | 677 | /* We can't do much more than wait for a reset */ |
685 | 678 | ||
686 | /* Note: currently the net2280 driver fails zero-length | 679 | /* |
687 | * submissions if DMA is enabled. */ | 680 | * Note: currently the net2280 driver fails zero-length |
688 | if (rc != -ESHUTDOWN && !(rc == -EOPNOTSUPP && | 681 | * submissions if DMA is enabled. |
689 | req->length == 0)) | 682 | */ |
683 | if (rc != -ESHUTDOWN && | ||
684 | !(rc == -EOPNOTSUPP && req->length == 0)) | ||
690 | WARNING(fsg, "error in submission: %s --> %d\n", | 685 | WARNING(fsg, "error in submission: %s --> %d\n", |
691 | ep->name, rc); | 686 | ep->name, rc); |
692 | } | 687 | } |
693 | } | 688 | } |
694 | 689 | ||
@@ -746,16 +741,20 @@ static int do_read(struct fsg_common *common) | |||
746 | unsigned int partial_page; | 741 | unsigned int partial_page; |
747 | ssize_t nread; | 742 | ssize_t nread; |
748 | 743 | ||
749 | /* Get the starting Logical Block Address and check that it's | 744 | /* |
750 | * not too big */ | 745 | * Get the starting Logical Block Address and check that it's |
746 | * not too big. | ||
747 | */ | ||
751 | if (common->cmnd[0] == READ_6) | 748 | if (common->cmnd[0] == READ_6) |
752 | lba = get_unaligned_be24(&common->cmnd[1]); | 749 | lba = get_unaligned_be24(&common->cmnd[1]); |
753 | else { | 750 | else { |
754 | lba = get_unaligned_be32(&common->cmnd[2]); | 751 | lba = get_unaligned_be32(&common->cmnd[2]); |
755 | 752 | ||
756 | /* We allow DPO (Disable Page Out = don't save data in the | 753 | /* |
754 | * We allow DPO (Disable Page Out = don't save data in the | ||
757 | * cache) and FUA (Force Unit Access = don't read from the | 755 | * cache) and FUA (Force Unit Access = don't read from the |
758 | * cache), but we don't implement them. */ | 756 | * cache), but we don't implement them. |
757 | */ | ||
759 | if ((common->cmnd[1] & ~0x18) != 0) { | 758 | if ((common->cmnd[1] & ~0x18) != 0) { |
760 | curlun->sense_data = SS_INVALID_FIELD_IN_CDB; | 759 | curlun->sense_data = SS_INVALID_FIELD_IN_CDB; |
761 | return -EINVAL; | 760 | return -EINVAL; |
@@ -773,22 +772,23 @@ static int do_read(struct fsg_common *common) | |||
773 | return -EIO; /* No default reply */ | 772 | return -EIO; /* No default reply */ |
774 | 773 | ||
775 | for (;;) { | 774 | for (;;) { |
776 | 775 | /* | |
777 | /* Figure out how much we need to read: | 776 | * Figure out how much we need to read: |
778 | * Try to read the remaining amount. | 777 | * Try to read the remaining amount. |
779 | * But don't read more than the buffer size. | 778 | * But don't read more than the buffer size. |
780 | * And don't try to read past the end of the file. | 779 | * And don't try to read past the end of the file. |
781 | * Finally, if we're not at a page boundary, don't read past | 780 | * Finally, if we're not at a page boundary, don't read past |
782 | * the next page. | 781 | * the next page. |
783 | * If this means reading 0 then we were asked to read past | 782 | * If this means reading 0 then we were asked to read past |
784 | * the end of file. */ | 783 | * the end of file. |
784 | */ | ||
785 | amount = min(amount_left, FSG_BUFLEN); | 785 | amount = min(amount_left, FSG_BUFLEN); |
786 | amount = min((loff_t) amount, | 786 | amount = min((loff_t)amount, |
787 | curlun->file_length - file_offset); | 787 | curlun->file_length - file_offset); |
788 | partial_page = file_offset & (PAGE_CACHE_SIZE - 1); | 788 | partial_page = file_offset & (PAGE_CACHE_SIZE - 1); |
789 | if (partial_page > 0) | 789 | if (partial_page > 0) |
790 | amount = min(amount, (unsigned int) PAGE_CACHE_SIZE - | 790 | amount = min(amount, (unsigned int)PAGE_CACHE_SIZE - |
791 | partial_page); | 791 | partial_page); |
792 | 792 | ||
793 | /* Wait for the next buffer to become available */ | 793 | /* Wait for the next buffer to become available */ |
794 | bh = common->next_buffhd_to_fill; | 794 | bh = common->next_buffhd_to_fill; |
@@ -798,8 +798,10 @@ static int do_read(struct fsg_common *common) | |||
798 | return rc; | 798 | return rc; |
799 | } | 799 | } |
800 | 800 | ||
801 | /* If we were asked to read past the end of file, | 801 | /* |
802 | * end with an empty buffer. */ | 802 | * If we were asked to read past the end of file, |
803 | * end with an empty buffer. | ||
804 | */ | ||
803 | if (amount == 0) { | 805 | if (amount == 0) { |
804 | curlun->sense_data = | 806 | curlun->sense_data = |
805 | SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE; | 807 | SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE; |
@@ -813,21 +815,19 @@ static int do_read(struct fsg_common *common) | |||
813 | /* Perform the read */ | 815 | /* Perform the read */ |
814 | file_offset_tmp = file_offset; | 816 | file_offset_tmp = file_offset; |
815 | nread = vfs_read(curlun->filp, | 817 | nread = vfs_read(curlun->filp, |
816 | (char __user *) bh->buf, | 818 | (char __user *)bh->buf, |
817 | amount, &file_offset_tmp); | 819 | amount, &file_offset_tmp); |
818 | VLDBG(curlun, "file read %u @ %llu -> %d\n", amount, | 820 | VLDBG(curlun, "file read %u @ %llu -> %d\n", amount, |
819 | (unsigned long long) file_offset, | 821 | (unsigned long long)file_offset, (int)nread); |
820 | (int) nread); | ||
821 | if (signal_pending(current)) | 822 | if (signal_pending(current)) |
822 | return -EINTR; | 823 | return -EINTR; |
823 | 824 | ||
824 | if (nread < 0) { | 825 | if (nread < 0) { |
825 | LDBG(curlun, "error in file read: %d\n", | 826 | LDBG(curlun, "error in file read: %d\n", (int)nread); |
826 | (int) nread); | ||
827 | nread = 0; | 827 | nread = 0; |
828 | } else if (nread < amount) { | 828 | } else if (nread < amount) { |
829 | LDBG(curlun, "partial file read: %d/%u\n", | 829 | LDBG(curlun, "partial file read: %d/%u\n", |
830 | (int) nread, amount); | 830 | (int)nread, amount); |
831 | nread -= (nread & 511); /* Round down to a block */ | 831 | nread -= (nread & 511); /* Round down to a block */ |
832 | } | 832 | } |
833 | file_offset += nread; | 833 | file_offset += nread; |
@@ -882,17 +882,21 @@ static int do_write(struct fsg_common *common) | |||
882 | curlun->filp->f_flags &= ~O_SYNC; /* Default is not to wait */ | 882 | curlun->filp->f_flags &= ~O_SYNC; /* Default is not to wait */ |
883 | spin_unlock(&curlun->filp->f_lock); | 883 | spin_unlock(&curlun->filp->f_lock); |
884 | 884 | ||
885 | /* Get the starting Logical Block Address and check that it's | 885 | /* |
886 | * not too big */ | 886 | * Get the starting Logical Block Address and check that it's |
887 | * not too big | ||
888 | */ | ||
887 | if (common->cmnd[0] == WRITE_6) | 889 | if (common->cmnd[0] == WRITE_6) |
888 | lba = get_unaligned_be24(&common->cmnd[1]); | 890 | lba = get_unaligned_be24(&common->cmnd[1]); |
889 | else { | 891 | else { |
890 | lba = get_unaligned_be32(&common->cmnd[2]); | 892 | lba = get_unaligned_be32(&common->cmnd[2]); |
891 | 893 | ||
892 | /* We allow DPO (Disable Page Out = don't save data in the | 894 | /* |
895 | * We allow DPO (Disable Page Out = don't save data in the | ||
893 | * cache) and FUA (Force Unit Access = write directly to the | 896 | * cache) and FUA (Force Unit Access = write directly to the |
894 | * medium). We don't implement DPO; we implement FUA by | 897 | * medium). We don't implement DPO; we implement FUA by |
895 | * performing synchronous output. */ | 898 | * performing synchronous output. |
899 | */ | ||
896 | if (common->cmnd[1] & ~0x18) { | 900 | if (common->cmnd[1] & ~0x18) { |
897 | curlun->sense_data = SS_INVALID_FIELD_IN_CDB; | 901 | curlun->sense_data = SS_INVALID_FIELD_IN_CDB; |
898 | return -EINVAL; | 902 | return -EINVAL; |
@@ -920,7 +924,8 @@ static int do_write(struct fsg_common *common) | |||
920 | bh = common->next_buffhd_to_fill; | 924 | bh = common->next_buffhd_to_fill; |
921 | if (bh->state == BUF_STATE_EMPTY && get_some_more) { | 925 | if (bh->state == BUF_STATE_EMPTY && get_some_more) { |
922 | 926 | ||
923 | /* Figure out how much we want to get: | 927 | /* |
928 | * Figure out how much we want to get: | ||
924 | * Try to get the remaining amount. | 929 | * Try to get the remaining amount. |
925 | * But don't get more than the buffer size. | 930 | * But don't get more than the buffer size. |
926 | * And don't try to go past the end of the file. | 931 | * And don't try to go past the end of the file. |
@@ -928,14 +933,15 @@ static int do_write(struct fsg_common *common) | |||
928 | * don't go past the next page. | 933 | * don't go past the next page. |
929 | * If this means getting 0, then we were asked | 934 | * If this means getting 0, then we were asked |
930 | * to write past the end of file. | 935 | * to write past the end of file. |
931 | * Finally, round down to a block boundary. */ | 936 | * Finally, round down to a block boundary. |
937 | */ | ||
932 | amount = min(amount_left_to_req, FSG_BUFLEN); | 938 | amount = min(amount_left_to_req, FSG_BUFLEN); |
933 | amount = min((loff_t) amount, curlun->file_length - | 939 | amount = min((loff_t)amount, |
934 | usb_offset); | 940 | curlun->file_length - usb_offset); |
935 | partial_page = usb_offset & (PAGE_CACHE_SIZE - 1); | 941 | partial_page = usb_offset & (PAGE_CACHE_SIZE - 1); |
936 | if (partial_page > 0) | 942 | if (partial_page > 0) |
937 | amount = min(amount, | 943 | amount = min(amount, |
938 | (unsigned int) PAGE_CACHE_SIZE - partial_page); | 944 | (unsigned int)PAGE_CACHE_SIZE - partial_page); |
939 | 945 | ||
940 | if (amount == 0) { | 946 | if (amount == 0) { |
941 | get_some_more = 0; | 947 | get_some_more = 0; |
@@ -945,11 +951,13 @@ static int do_write(struct fsg_common *common) | |||
945 | curlun->info_valid = 1; | 951 | curlun->info_valid = 1; |
946 | continue; | 952 | continue; |
947 | } | 953 | } |
948 | amount -= (amount & 511); | 954 | amount -= amount & 511; |
949 | if (amount == 0) { | 955 | if (amount == 0) { |
950 | 956 | ||
951 | /* Why were we were asked to transfer a | 957 | /* |
952 | * partial block? */ | 958 | * Why were we were asked to transfer a |
959 | * partial block? | ||
960 | */ | ||
953 | get_some_more = 0; | 961 | get_some_more = 0; |
954 | continue; | 962 | continue; |
955 | } | 963 | } |
@@ -961,14 +969,15 @@ static int do_write(struct fsg_common *common) | |||
961 | if (amount_left_to_req == 0) | 969 | if (amount_left_to_req == 0) |
962 | get_some_more = 0; | 970 | get_some_more = 0; |
963 | 971 | ||
964 | /* amount is always divisible by 512, hence by | 972 | /* |
965 | * the bulk-out maxpacket size */ | 973 | * amount is always divisible by 512, hence by |
974 | * the bulk-out maxpacket size | ||
975 | */ | ||
966 | bh->outreq->length = amount; | 976 | bh->outreq->length = amount; |
967 | bh->bulk_out_intended_length = amount; | 977 | bh->bulk_out_intended_length = amount; |
968 | bh->outreq->short_not_ok = 1; | 978 | bh->outreq->short_not_ok = 1; |
969 | if (!start_out_transfer(common, bh)) | 979 | if (!start_out_transfer(common, bh)) |
970 | /* Don't know what to do if | 980 | /* Dunno what to do if common->fsg is NULL */ |
971 | * common->fsg is NULL */ | ||
972 | return -EIO; | 981 | return -EIO; |
973 | common->next_buffhd_to_fill = bh->next; | 982 | common->next_buffhd_to_fill = bh->next; |
974 | continue; | 983 | continue; |
@@ -994,30 +1003,29 @@ static int do_write(struct fsg_common *common) | |||
994 | amount = bh->outreq->actual; | 1003 | amount = bh->outreq->actual; |
995 | if (curlun->file_length - file_offset < amount) { | 1004 | if (curlun->file_length - file_offset < amount) { |
996 | LERROR(curlun, | 1005 | LERROR(curlun, |
997 | "write %u @ %llu beyond end %llu\n", | 1006 | "write %u @ %llu beyond end %llu\n", |
998 | amount, (unsigned long long) file_offset, | 1007 | amount, (unsigned long long)file_offset, |
999 | (unsigned long long) curlun->file_length); | 1008 | (unsigned long long)curlun->file_length); |
1000 | amount = curlun->file_length - file_offset; | 1009 | amount = curlun->file_length - file_offset; |
1001 | } | 1010 | } |
1002 | 1011 | ||
1003 | /* Perform the write */ | 1012 | /* Perform the write */ |
1004 | file_offset_tmp = file_offset; | 1013 | file_offset_tmp = file_offset; |
1005 | nwritten = vfs_write(curlun->filp, | 1014 | nwritten = vfs_write(curlun->filp, |
1006 | (char __user *) bh->buf, | 1015 | (char __user *)bh->buf, |
1007 | amount, &file_offset_tmp); | 1016 | amount, &file_offset_tmp); |
1008 | VLDBG(curlun, "file write %u @ %llu -> %d\n", amount, | 1017 | VLDBG(curlun, "file write %u @ %llu -> %d\n", amount, |
1009 | (unsigned long long) file_offset, | 1018 | (unsigned long long)file_offset, (int)nwritten); |
1010 | (int) nwritten); | ||
1011 | if (signal_pending(current)) | 1019 | if (signal_pending(current)) |
1012 | return -EINTR; /* Interrupted! */ | 1020 | return -EINTR; /* Interrupted! */ |
1013 | 1021 | ||
1014 | if (nwritten < 0) { | 1022 | if (nwritten < 0) { |
1015 | LDBG(curlun, "error in file write: %d\n", | 1023 | LDBG(curlun, "error in file write: %d\n", |
1016 | (int) nwritten); | 1024 | (int)nwritten); |
1017 | nwritten = 0; | 1025 | nwritten = 0; |
1018 | } else if (nwritten < amount) { | 1026 | } else if (nwritten < amount) { |
1019 | LDBG(curlun, "partial file write: %d/%u\n", | 1027 | LDBG(curlun, "partial file write: %d/%u\n", |
1020 | (int) nwritten, amount); | 1028 | (int)nwritten, amount); |
1021 | nwritten -= (nwritten & 511); | 1029 | nwritten -= (nwritten & 511); |
1022 | /* Round down to a block */ | 1030 | /* Round down to a block */ |
1023 | } | 1031 | } |
@@ -1090,16 +1098,20 @@ static int do_verify(struct fsg_common *common) | |||
1090 | unsigned int amount; | 1098 | unsigned int amount; |
1091 | ssize_t nread; | 1099 | ssize_t nread; |
1092 | 1100 | ||
1093 | /* Get the starting Logical Block Address and check that it's | 1101 | /* |
1094 | * not too big */ | 1102 | * Get the starting Logical Block Address and check that it's |
1103 | * not too big. | ||
1104 | */ | ||
1095 | lba = get_unaligned_be32(&common->cmnd[2]); | 1105 | lba = get_unaligned_be32(&common->cmnd[2]); |
1096 | if (lba >= curlun->num_sectors) { | 1106 | if (lba >= curlun->num_sectors) { |
1097 | curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE; | 1107 | curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE; |
1098 | return -EINVAL; | 1108 | return -EINVAL; |
1099 | } | 1109 | } |
1100 | 1110 | ||
1101 | /* We allow DPO (Disable Page Out = don't save data in the | 1111 | /* |
1102 | * cache) but we don't implement it. */ | 1112 | * We allow DPO (Disable Page Out = don't save data in the |
1113 | * cache) but we don't implement it. | ||
1114 | */ | ||
1103 | if (common->cmnd[1] & ~0x10) { | 1115 | if (common->cmnd[1] & ~0x10) { |
1104 | curlun->sense_data = SS_INVALID_FIELD_IN_CDB; | 1116 | curlun->sense_data = SS_INVALID_FIELD_IN_CDB; |
1105 | return -EINVAL; | 1117 | return -EINVAL; |
@@ -1124,16 +1136,17 @@ static int do_verify(struct fsg_common *common) | |||
1124 | 1136 | ||
1125 | /* Just try to read the requested blocks */ | 1137 | /* Just try to read the requested blocks */ |
1126 | while (amount_left > 0) { | 1138 | while (amount_left > 0) { |
1127 | 1139 | /* | |
1128 | /* Figure out how much we need to read: | 1140 | * Figure out how much we need to read: |
1129 | * Try to read the remaining amount, but not more than | 1141 | * Try to read the remaining amount, but not more than |
1130 | * the buffer size. | 1142 | * the buffer size. |
1131 | * And don't try to read past the end of the file. | 1143 | * And don't try to read past the end of the file. |
1132 | * If this means reading 0 then we were asked to read | 1144 | * If this means reading 0 then we were asked to read |
1133 | * past the end of file. */ | 1145 | * past the end of file. |
1146 | */ | ||
1134 | amount = min(amount_left, FSG_BUFLEN); | 1147 | amount = min(amount_left, FSG_BUFLEN); |
1135 | amount = min((loff_t) amount, | 1148 | amount = min((loff_t)amount, |
1136 | curlun->file_length - file_offset); | 1149 | curlun->file_length - file_offset); |
1137 | if (amount == 0) { | 1150 | if (amount == 0) { |
1138 | curlun->sense_data = | 1151 | curlun->sense_data = |
1139 | SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE; | 1152 | SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE; |
@@ -1154,13 +1167,12 @@ static int do_verify(struct fsg_common *common) | |||
1154 | return -EINTR; | 1167 | return -EINTR; |
1155 | 1168 | ||
1156 | if (nread < 0) { | 1169 | if (nread < 0) { |
1157 | LDBG(curlun, "error in file verify: %d\n", | 1170 | LDBG(curlun, "error in file verify: %d\n", (int)nread); |
1158 | (int) nread); | ||
1159 | nread = 0; | 1171 | nread = 0; |
1160 | } else if (nread < amount) { | 1172 | } else if (nread < amount) { |
1161 | LDBG(curlun, "partial file verify: %d/%u\n", | 1173 | LDBG(curlun, "partial file verify: %d/%u\n", |
1162 | (int) nread, amount); | 1174 | (int)nread, amount); |
1163 | nread -= (nread & 511); /* Round down to a sector */ | 1175 | nread -= nread & 511; /* Round down to a sector */ |
1164 | } | 1176 | } |
1165 | if (nread == 0) { | 1177 | if (nread == 0) { |
1166 | curlun->sense_data = SS_UNRECOVERED_READ_ERROR; | 1178 | curlun->sense_data = SS_UNRECOVERED_READ_ERROR; |
@@ -1202,7 +1214,6 @@ static int do_inquiry(struct fsg_common *common, struct fsg_buffhd *bh) | |||
1202 | return 36; | 1214 | return 36; |
1203 | } | 1215 | } |
1204 | 1216 | ||
1205 | |||
1206 | static int do_request_sense(struct fsg_common *common, struct fsg_buffhd *bh) | 1217 | static int do_request_sense(struct fsg_common *common, struct fsg_buffhd *bh) |
1207 | { | 1218 | { |
1208 | struct fsg_lun *curlun = common->curlun; | 1219 | struct fsg_lun *curlun = common->curlun; |
@@ -1256,13 +1267,12 @@ static int do_request_sense(struct fsg_common *common, struct fsg_buffhd *bh) | |||
1256 | return 18; | 1267 | return 18; |
1257 | } | 1268 | } |
1258 | 1269 | ||
1259 | |||
1260 | static int do_read_capacity(struct fsg_common *common, struct fsg_buffhd *bh) | 1270 | static int do_read_capacity(struct fsg_common *common, struct fsg_buffhd *bh) |
1261 | { | 1271 | { |
1262 | struct fsg_lun *curlun = common->curlun; | 1272 | struct fsg_lun *curlun = common->curlun; |
1263 | u32 lba = get_unaligned_be32(&common->cmnd[2]); | 1273 | u32 lba = get_unaligned_be32(&common->cmnd[2]); |
1264 | int pmi = common->cmnd[8]; | 1274 | int pmi = common->cmnd[8]; |
1265 | u8 *buf = (u8 *) bh->buf; | 1275 | u8 *buf = (u8 *)bh->buf; |
1266 | 1276 | ||
1267 | /* Check the PMI and LBA fields */ | 1277 | /* Check the PMI and LBA fields */ |
1268 | if (pmi > 1 || (pmi == 0 && lba != 0)) { | 1278 | if (pmi > 1 || (pmi == 0 && lba != 0)) { |
@@ -1276,13 +1286,12 @@ static int do_read_capacity(struct fsg_common *common, struct fsg_buffhd *bh) | |||
1276 | return 8; | 1286 | return 8; |
1277 | } | 1287 | } |
1278 | 1288 | ||
1279 | |||
1280 | static int do_read_header(struct fsg_common *common, struct fsg_buffhd *bh) | 1289 | static int do_read_header(struct fsg_common *common, struct fsg_buffhd *bh) |
1281 | { | 1290 | { |
1282 | struct fsg_lun *curlun = common->curlun; | 1291 | struct fsg_lun *curlun = common->curlun; |
1283 | int msf = common->cmnd[1] & 0x02; | 1292 | int msf = common->cmnd[1] & 0x02; |
1284 | u32 lba = get_unaligned_be32(&common->cmnd[2]); | 1293 | u32 lba = get_unaligned_be32(&common->cmnd[2]); |
1285 | u8 *buf = (u8 *) bh->buf; | 1294 | u8 *buf = (u8 *)bh->buf; |
1286 | 1295 | ||
1287 | if (common->cmnd[1] & ~0x02) { /* Mask away MSF */ | 1296 | if (common->cmnd[1] & ~0x02) { /* Mask away MSF */ |
1288 | curlun->sense_data = SS_INVALID_FIELD_IN_CDB; | 1297 | curlun->sense_data = SS_INVALID_FIELD_IN_CDB; |
@@ -1299,13 +1308,12 @@ static int do_read_header(struct fsg_common *common, struct fsg_buffhd *bh) | |||
1299 | return 8; | 1308 | return 8; |
1300 | } | 1309 | } |
1301 | 1310 | ||
1302 | |||
1303 | static int do_read_toc(struct fsg_common *common, struct fsg_buffhd *bh) | 1311 | static int do_read_toc(struct fsg_common *common, struct fsg_buffhd *bh) |
1304 | { | 1312 | { |
1305 | struct fsg_lun *curlun = common->curlun; | 1313 | struct fsg_lun *curlun = common->curlun; |
1306 | int msf = common->cmnd[1] & 0x02; | 1314 | int msf = common->cmnd[1] & 0x02; |
1307 | int start_track = common->cmnd[6]; | 1315 | int start_track = common->cmnd[6]; |
1308 | u8 *buf = (u8 *) bh->buf; | 1316 | u8 *buf = (u8 *)bh->buf; |
1309 | 1317 | ||
1310 | if ((common->cmnd[1] & ~0x02) != 0 || /* Mask away MSF */ | 1318 | if ((common->cmnd[1] & ~0x02) != 0 || /* Mask away MSF */ |
1311 | start_track > 1) { | 1319 | start_track > 1) { |
@@ -1327,7 +1335,6 @@ static int do_read_toc(struct fsg_common *common, struct fsg_buffhd *bh) | |||
1327 | return 20; | 1335 | return 20; |
1328 | } | 1336 | } |
1329 | 1337 | ||
1330 | |||
1331 | static int do_mode_sense(struct fsg_common *common, struct fsg_buffhd *bh) | 1338 | static int do_mode_sense(struct fsg_common *common, struct fsg_buffhd *bh) |
1332 | { | 1339 | { |
1333 | struct fsg_lun *curlun = common->curlun; | 1340 | struct fsg_lun *curlun = common->curlun; |
@@ -1352,10 +1359,12 @@ static int do_mode_sense(struct fsg_common *common, struct fsg_buffhd *bh) | |||
1352 | changeable_values = (pc == 1); | 1359 | changeable_values = (pc == 1); |
1353 | all_pages = (page_code == 0x3f); | 1360 | all_pages = (page_code == 0x3f); |
1354 | 1361 | ||
1355 | /* Write the mode parameter header. Fixed values are: default | 1362 | /* |
1363 | * Write the mode parameter header. Fixed values are: default | ||
1356 | * medium type, no cache control (DPOFUA), and no block descriptors. | 1364 | * medium type, no cache control (DPOFUA), and no block descriptors. |
1357 | * The only variable value is the WriteProtect bit. We will fill in | 1365 | * The only variable value is the WriteProtect bit. We will fill in |
1358 | * the mode data length later. */ | 1366 | * the mode data length later. |
1367 | */ | ||
1359 | memset(buf, 0, 8); | 1368 | memset(buf, 0, 8); |
1360 | if (mscmnd == MODE_SENSE) { | 1369 | if (mscmnd == MODE_SENSE) { |
1361 | buf[2] = (curlun->ro ? 0x80 : 0x00); /* WP, DPOFUA */ | 1370 | buf[2] = (curlun->ro ? 0x80 : 0x00); /* WP, DPOFUA */ |
@@ -1369,8 +1378,10 @@ static int do_mode_sense(struct fsg_common *common, struct fsg_buffhd *bh) | |||
1369 | 1378 | ||
1370 | /* No block descriptors */ | 1379 | /* No block descriptors */ |
1371 | 1380 | ||
1372 | /* The mode pages, in numerical order. The only page we support | 1381 | /* |
1373 | * is the Caching page. */ | 1382 | * The mode pages, in numerical order. The only page we support |
1383 | * is the Caching page. | ||
1384 | */ | ||
1374 | if (page_code == 0x08 || all_pages) { | 1385 | if (page_code == 0x08 || all_pages) { |
1375 | valid_page = 1; | 1386 | valid_page = 1; |
1376 | buf[0] = 0x08; /* Page code */ | 1387 | buf[0] = 0x08; /* Page code */ |
@@ -1392,8 +1403,10 @@ static int do_mode_sense(struct fsg_common *common, struct fsg_buffhd *bh) | |||
1392 | buf += 12; | 1403 | buf += 12; |
1393 | } | 1404 | } |
1394 | 1405 | ||
1395 | /* Check that a valid page was requested and the mode data length | 1406 | /* |
1396 | * isn't too long. */ | 1407 | * Check that a valid page was requested and the mode data length |
1408 | * isn't too long. | ||
1409 | */ | ||
1397 | len = buf - buf0; | 1410 | len = buf - buf0; |
1398 | if (!valid_page || len > limit) { | 1411 | if (!valid_page || len > limit) { |
1399 | curlun->sense_data = SS_INVALID_FIELD_IN_CDB; | 1412 | curlun->sense_data = SS_INVALID_FIELD_IN_CDB; |
@@ -1408,7 +1421,6 @@ static int do_mode_sense(struct fsg_common *common, struct fsg_buffhd *bh) | |||
1408 | return len; | 1421 | return len; |
1409 | } | 1422 | } |
1410 | 1423 | ||
1411 | |||
1412 | static int do_start_stop(struct fsg_common *common) | 1424 | static int do_start_stop(struct fsg_common *common) |
1413 | { | 1425 | { |
1414 | struct fsg_lun *curlun = common->curlun; | 1426 | struct fsg_lun *curlun = common->curlun; |
@@ -1428,8 +1440,10 @@ static int do_start_stop(struct fsg_common *common) | |||
1428 | loej = common->cmnd[4] & 0x02; | 1440 | loej = common->cmnd[4] & 0x02; |
1429 | start = common->cmnd[4] & 0x01; | 1441 | start = common->cmnd[4] & 0x01; |
1430 | 1442 | ||
1431 | /* Our emulation doesn't support mounting; the medium is | 1443 | /* |
1432 | * available for use as soon as it is loaded. */ | 1444 | * Our emulation doesn't support mounting; the medium is |
1445 | * available for use as soon as it is loaded. | ||
1446 | */ | ||
1433 | if (start) { | 1447 | if (start) { |
1434 | if (!fsg_lun_is_open(curlun)) { | 1448 | if (!fsg_lun_is_open(curlun)) { |
1435 | curlun->sense_data = SS_MEDIUM_NOT_PRESENT; | 1449 | curlun->sense_data = SS_MEDIUM_NOT_PRESENT; |
@@ -1470,7 +1484,6 @@ static int do_start_stop(struct fsg_common *common) | |||
1470 | : 0; | 1484 | : 0; |
1471 | } | 1485 | } |
1472 | 1486 | ||
1473 | |||
1474 | static int do_prevent_allow(struct fsg_common *common) | 1487 | static int do_prevent_allow(struct fsg_common *common) |
1475 | { | 1488 | { |
1476 | struct fsg_lun *curlun = common->curlun; | 1489 | struct fsg_lun *curlun = common->curlun; |
@@ -1495,7 +1508,6 @@ static int do_prevent_allow(struct fsg_common *common) | |||
1495 | return 0; | 1508 | return 0; |
1496 | } | 1509 | } |
1497 | 1510 | ||
1498 | |||
1499 | static int do_read_format_capacities(struct fsg_common *common, | 1511 | static int do_read_format_capacities(struct fsg_common *common, |
1500 | struct fsg_buffhd *bh) | 1512 | struct fsg_buffhd *bh) |
1501 | { | 1513 | { |
@@ -1513,7 +1525,6 @@ static int do_read_format_capacities(struct fsg_common *common, | |||
1513 | return 12; | 1525 | return 12; |
1514 | } | 1526 | } |
1515 | 1527 | ||
1516 | |||
1517 | static int do_mode_select(struct fsg_common *common, struct fsg_buffhd *bh) | 1528 | static int do_mode_select(struct fsg_common *common, struct fsg_buffhd *bh) |
1518 | { | 1529 | { |
1519 | struct fsg_lun *curlun = common->curlun; | 1530 | struct fsg_lun *curlun = common->curlun; |
@@ -1595,7 +1606,7 @@ static int pad_with_zeros(struct fsg_dev *fsg) | |||
1595 | bh->inreq->length = nsend; | 1606 | bh->inreq->length = nsend; |
1596 | bh->inreq->zero = 0; | 1607 | bh->inreq->zero = 0; |
1597 | start_transfer(fsg, fsg->bulk_in, bh->inreq, | 1608 | start_transfer(fsg, fsg->bulk_in, bh->inreq, |
1598 | &bh->inreq_busy, &bh->state); | 1609 | &bh->inreq_busy, &bh->state); |
1599 | bh = fsg->common->next_buffhd_to_fill = bh->next; | 1610 | bh = fsg->common->next_buffhd_to_fill = bh->next; |
1600 | fsg->common->usb_amount_left -= nsend; | 1611 | fsg->common->usb_amount_left -= nsend; |
1601 | nkeep = 0; | 1612 | nkeep = 0; |
@@ -1621,7 +1632,7 @@ static int throw_away_data(struct fsg_common *common) | |||
1621 | 1632 | ||
1622 | /* A short packet or an error ends everything */ | 1633 | /* A short packet or an error ends everything */ |
1623 | if (bh->outreq->actual != bh->outreq->length || | 1634 | if (bh->outreq->actual != bh->outreq->length || |
1624 | bh->outreq->status != 0) { | 1635 | bh->outreq->status != 0) { |
1625 | raise_exception(common, | 1636 | raise_exception(common, |
1626 | FSG_STATE_ABORT_BULK_OUT); | 1637 | FSG_STATE_ABORT_BULK_OUT); |
1627 | return -EINTR; | 1638 | return -EINTR; |
@@ -1635,14 +1646,15 @@ static int throw_away_data(struct fsg_common *common) | |||
1635 | && common->usb_amount_left > 0) { | 1646 | && common->usb_amount_left > 0) { |
1636 | amount = min(common->usb_amount_left, FSG_BUFLEN); | 1647 | amount = min(common->usb_amount_left, FSG_BUFLEN); |
1637 | 1648 | ||
1638 | /* amount is always divisible by 512, hence by | 1649 | /* |
1639 | * the bulk-out maxpacket size */ | 1650 | * amount is always divisible by 512, hence by |
1651 | * the bulk-out maxpacket size. | ||
1652 | */ | ||
1640 | bh->outreq->length = amount; | 1653 | bh->outreq->length = amount; |
1641 | bh->bulk_out_intended_length = amount; | 1654 | bh->bulk_out_intended_length = amount; |
1642 | bh->outreq->short_not_ok = 1; | 1655 | bh->outreq->short_not_ok = 1; |
1643 | if (!start_out_transfer(common, bh)) | 1656 | if (!start_out_transfer(common, bh)) |
1644 | /* Don't know what to do if | 1657 | /* Dunno what to do if common->fsg is NULL */ |
1645 | * common->fsg is NULL */ | ||
1646 | return -EIO; | 1658 | return -EIO; |
1647 | common->next_buffhd_to_fill = bh->next; | 1659 | common->next_buffhd_to_fill = bh->next; |
1648 | common->usb_amount_left -= amount; | 1660 | common->usb_amount_left -= amount; |
@@ -1657,7 +1669,6 @@ static int throw_away_data(struct fsg_common *common) | |||
1657 | return 0; | 1669 | return 0; |
1658 | } | 1670 | } |
1659 | 1671 | ||
1660 | |||
1661 | static int finish_reply(struct fsg_common *common) | 1672 | static int finish_reply(struct fsg_common *common) |
1662 | { | 1673 | { |
1663 | struct fsg_buffhd *bh = common->next_buffhd_to_fill; | 1674 | struct fsg_buffhd *bh = common->next_buffhd_to_fill; |
@@ -1667,10 +1678,12 @@ static int finish_reply(struct fsg_common *common) | |||
1667 | case DATA_DIR_NONE: | 1678 | case DATA_DIR_NONE: |
1668 | break; /* Nothing to send */ | 1679 | break; /* Nothing to send */ |
1669 | 1680 | ||
1670 | /* If we don't know whether the host wants to read or write, | 1681 | /* |
1682 | * If we don't know whether the host wants to read or write, | ||
1671 | * this must be CB or CBI with an unknown command. We mustn't | 1683 | * this must be CB or CBI with an unknown command. We mustn't |
1672 | * try to send or receive any data. So stall both bulk pipes | 1684 | * try to send or receive any data. So stall both bulk pipes |
1673 | * if we can and wait for a reset. */ | 1685 | * if we can and wait for a reset. |
1686 | */ | ||
1674 | case DATA_DIR_UNKNOWN: | 1687 | case DATA_DIR_UNKNOWN: |
1675 | if (!common->can_stall) { | 1688 | if (!common->can_stall) { |
1676 | /* Nothing */ | 1689 | /* Nothing */ |
@@ -1695,9 +1708,11 @@ static int finish_reply(struct fsg_common *common) | |||
1695 | return -EIO; | 1708 | return -EIO; |
1696 | common->next_buffhd_to_fill = bh->next; | 1709 | common->next_buffhd_to_fill = bh->next; |
1697 | 1710 | ||
1698 | /* For Bulk-only, if we're allowed to stall then send the | 1711 | /* |
1712 | * For Bulk-only, if we're allowed to stall then send the | ||
1699 | * short packet and halt the bulk-in endpoint. If we can't | 1713 | * short packet and halt the bulk-in endpoint. If we can't |
1700 | * stall, pad out the remaining data with 0's. */ | 1714 | * stall, pad out the remaining data with 0's. |
1715 | */ | ||
1701 | } else if (common->can_stall) { | 1716 | } else if (common->can_stall) { |
1702 | bh->inreq->zero = 1; | 1717 | bh->inreq->zero = 1; |
1703 | if (!start_in_transfer(common, bh)) | 1718 | if (!start_in_transfer(common, bh)) |
@@ -1715,8 +1730,10 @@ static int finish_reply(struct fsg_common *common) | |||
1715 | } | 1730 | } |
1716 | break; | 1731 | break; |
1717 | 1732 | ||
1718 | /* We have processed all we want from the data the host has sent. | 1733 | /* |
1719 | * There may still be outstanding bulk-out requests. */ | 1734 | * We have processed all we want from the data the host has sent. |
1735 | * There may still be outstanding bulk-out requests. | ||
1736 | */ | ||
1720 | case DATA_DIR_FROM_HOST: | 1737 | case DATA_DIR_FROM_HOST: |
1721 | if (common->residue == 0) { | 1738 | if (common->residue == 0) { |
1722 | /* Nothing to receive */ | 1739 | /* Nothing to receive */ |
@@ -1726,12 +1743,14 @@ static int finish_reply(struct fsg_common *common) | |||
1726 | raise_exception(common, FSG_STATE_ABORT_BULK_OUT); | 1743 | raise_exception(common, FSG_STATE_ABORT_BULK_OUT); |
1727 | rc = -EINTR; | 1744 | rc = -EINTR; |
1728 | 1745 | ||
1729 | /* We haven't processed all the incoming data. Even though | 1746 | /* |
1747 | * We haven't processed all the incoming data. Even though | ||
1730 | * we may be allowed to stall, doing so would cause a race. | 1748 | * we may be allowed to stall, doing so would cause a race. |
1731 | * The controller may already have ACK'ed all the remaining | 1749 | * The controller may already have ACK'ed all the remaining |
1732 | * bulk-out packets, in which case the host wouldn't see a | 1750 | * bulk-out packets, in which case the host wouldn't see a |
1733 | * STALL. Not realizing the endpoint was halted, it wouldn't | 1751 | * STALL. Not realizing the endpoint was halted, it wouldn't |
1734 | * clear the halt -- leading to problems later on. */ | 1752 | * clear the halt -- leading to problems later on. |
1753 | */ | ||
1735 | #if 0 | 1754 | #if 0 |
1736 | } else if (common->can_stall) { | 1755 | } else if (common->can_stall) { |
1737 | if (fsg_is_set(common)) | 1756 | if (fsg_is_set(common)) |
@@ -1741,8 +1760,10 @@ static int finish_reply(struct fsg_common *common) | |||
1741 | rc = -EINTR; | 1760 | rc = -EINTR; |
1742 | #endif | 1761 | #endif |
1743 | 1762 | ||
1744 | /* We can't stall. Read in the excess data and throw it | 1763 | /* |
1745 | * all away. */ | 1764 | * We can't stall. Read in the excess data and throw it |
1765 | * all away. | ||
1766 | */ | ||
1746 | } else { | 1767 | } else { |
1747 | rc = throw_away_data(common); | 1768 | rc = throw_away_data(common); |
1748 | } | 1769 | } |
@@ -1751,7 +1772,6 @@ static int finish_reply(struct fsg_common *common) | |||
1751 | return rc; | 1772 | return rc; |
1752 | } | 1773 | } |
1753 | 1774 | ||
1754 | |||
1755 | static int send_status(struct fsg_common *common) | 1775 | static int send_status(struct fsg_common *common) |
1756 | { | 1776 | { |
1757 | struct fsg_lun *curlun = common->curlun; | 1777 | struct fsg_lun *curlun = common->curlun; |
@@ -1810,11 +1830,13 @@ static int send_status(struct fsg_common *common) | |||
1810 | 1830 | ||
1811 | /*-------------------------------------------------------------------------*/ | 1831 | /*-------------------------------------------------------------------------*/ |
1812 | 1832 | ||
1813 | /* Check whether the command is properly formed and whether its data size | 1833 | /* |
1814 | * and direction agree with the values we already have. */ | 1834 | * Check whether the command is properly formed and whether its data size |
1835 | * and direction agree with the values we already have. | ||
1836 | */ | ||
1815 | static int check_command(struct fsg_common *common, int cmnd_size, | 1837 | static int check_command(struct fsg_common *common, int cmnd_size, |
1816 | enum data_direction data_dir, unsigned int mask, | 1838 | enum data_direction data_dir, unsigned int mask, |
1817 | int needs_medium, const char *name) | 1839 | int needs_medium, const char *name) |
1818 | { | 1840 | { |
1819 | int i; | 1841 | int i; |
1820 | int lun = common->cmnd[1] >> 5; | 1842 | int lun = common->cmnd[1] >> 5; |
@@ -1825,19 +1847,23 @@ static int check_command(struct fsg_common *common, int cmnd_size, | |||
1825 | hdlen[0] = 0; | 1847 | hdlen[0] = 0; |
1826 | if (common->data_dir != DATA_DIR_UNKNOWN) | 1848 | if (common->data_dir != DATA_DIR_UNKNOWN) |
1827 | sprintf(hdlen, ", H%c=%u", dirletter[(int) common->data_dir], | 1849 | sprintf(hdlen, ", H%c=%u", dirletter[(int) common->data_dir], |
1828 | common->data_size); | 1850 | common->data_size); |
1829 | VDBG(common, "SCSI command: %s; Dc=%d, D%c=%u; Hc=%d%s\n", | 1851 | VDBG(common, "SCSI command: %s; Dc=%d, D%c=%u; Hc=%d%s\n", |
1830 | name, cmnd_size, dirletter[(int) data_dir], | 1852 | name, cmnd_size, dirletter[(int) data_dir], |
1831 | common->data_size_from_cmnd, common->cmnd_size, hdlen); | 1853 | common->data_size_from_cmnd, common->cmnd_size, hdlen); |
1832 | 1854 | ||
1833 | /* We can't reply at all until we know the correct data direction | 1855 | /* |
1834 | * and size. */ | 1856 | * We can't reply at all until we know the correct data direction |
1857 | * and size. | ||
1858 | */ | ||
1835 | if (common->data_size_from_cmnd == 0) | 1859 | if (common->data_size_from_cmnd == 0) |
1836 | data_dir = DATA_DIR_NONE; | 1860 | data_dir = DATA_DIR_NONE; |
1837 | if (common->data_size < common->data_size_from_cmnd) { | 1861 | if (common->data_size < common->data_size_from_cmnd) { |
1838 | /* Host data size < Device data size is a phase error. | 1862 | /* |
1863 | * Host data size < Device data size is a phase error. | ||
1839 | * Carry out the command, but only transfer as much as | 1864 | * Carry out the command, but only transfer as much as |
1840 | * we are allowed. */ | 1865 | * we are allowed. |
1866 | */ | ||
1841 | common->data_size_from_cmnd = common->data_size; | 1867 | common->data_size_from_cmnd = common->data_size; |
1842 | common->phase_error = 1; | 1868 | common->phase_error = 1; |
1843 | } | 1869 | } |
@@ -1845,8 +1871,7 @@ static int check_command(struct fsg_common *common, int cmnd_size, | |||
1845 | common->usb_amount_left = common->data_size; | 1871 | common->usb_amount_left = common->data_size; |
1846 | 1872 | ||
1847 | /* Conflicting data directions is a phase error */ | 1873 | /* Conflicting data directions is a phase error */ |
1848 | if (common->data_dir != data_dir | 1874 | if (common->data_dir != data_dir && common->data_size_from_cmnd > 0) { |
1849 | && common->data_size_from_cmnd > 0) { | ||
1850 | common->phase_error = 1; | 1875 | common->phase_error = 1; |
1851 | return -EINVAL; | 1876 | return -EINVAL; |
1852 | } | 1877 | } |
@@ -1854,7 +1879,8 @@ static int check_command(struct fsg_common *common, int cmnd_size, | |||
1854 | /* Verify the length of the command itself */ | 1879 | /* Verify the length of the command itself */ |
1855 | if (cmnd_size != common->cmnd_size) { | 1880 | if (cmnd_size != common->cmnd_size) { |
1856 | 1881 | ||
1857 | /* Special case workaround: There are plenty of buggy SCSI | 1882 | /* |
1883 | * Special case workaround: There are plenty of buggy SCSI | ||
1858 | * implementations. Many have issues with cbw->Length | 1884 | * implementations. Many have issues with cbw->Length |
1859 | * field passing a wrong command size. For those cases we | 1885 | * field passing a wrong command size. For those cases we |
1860 | * always try to work around the problem by using the length | 1886 | * always try to work around the problem by using the length |
@@ -1896,8 +1922,10 @@ static int check_command(struct fsg_common *common, int cmnd_size, | |||
1896 | curlun = NULL; | 1922 | curlun = NULL; |
1897 | common->bad_lun_okay = 0; | 1923 | common->bad_lun_okay = 0; |
1898 | 1924 | ||
1899 | /* INQUIRY and REQUEST SENSE commands are explicitly allowed | 1925 | /* |
1900 | * to use unsupported LUNs; all others may not. */ | 1926 | * INQUIRY and REQUEST SENSE commands are explicitly allowed |
1927 | * to use unsupported LUNs; all others may not. | ||
1928 | */ | ||
1901 | if (common->cmnd[0] != INQUIRY && | 1929 | if (common->cmnd[0] != INQUIRY && |
1902 | common->cmnd[0] != REQUEST_SENSE) { | 1930 | common->cmnd[0] != REQUEST_SENSE) { |
1903 | DBG(common, "unsupported LUN %d\n", common->lun); | 1931 | DBG(common, "unsupported LUN %d\n", common->lun); |
@@ -1905,11 +1933,13 @@ static int check_command(struct fsg_common *common, int cmnd_size, | |||
1905 | } | 1933 | } |
1906 | } | 1934 | } |
1907 | 1935 | ||
1908 | /* If a unit attention condition exists, only INQUIRY and | 1936 | /* |
1909 | * REQUEST SENSE commands are allowed; anything else must fail. */ | 1937 | * If a unit attention condition exists, only INQUIRY and |
1938 | * REQUEST SENSE commands are allowed; anything else must fail. | ||
1939 | */ | ||
1910 | if (curlun && curlun->unit_attention_data != SS_NO_SENSE && | 1940 | if (curlun && curlun->unit_attention_data != SS_NO_SENSE && |
1911 | common->cmnd[0] != INQUIRY && | 1941 | common->cmnd[0] != INQUIRY && |
1912 | common->cmnd[0] != REQUEST_SENSE) { | 1942 | common->cmnd[0] != REQUEST_SENSE) { |
1913 | curlun->sense_data = curlun->unit_attention_data; | 1943 | curlun->sense_data = curlun->unit_attention_data; |
1914 | curlun->unit_attention_data = SS_NO_SENSE; | 1944 | curlun->unit_attention_data = SS_NO_SENSE; |
1915 | return -EINVAL; | 1945 | return -EINVAL; |
@@ -1935,7 +1965,6 @@ static int check_command(struct fsg_common *common, int cmnd_size, | |||
1935 | return 0; | 1965 | return 0; |
1936 | } | 1966 | } |
1937 | 1967 | ||
1938 | |||
1939 | static int do_scsi_command(struct fsg_common *common) | 1968 | static int do_scsi_command(struct fsg_common *common) |
1940 | { | 1969 | { |
1941 | struct fsg_buffhd *bh; | 1970 | struct fsg_buffhd *bh; |
@@ -2123,8 +2152,10 @@ static int do_scsi_command(struct fsg_common *common) | |||
2123 | "TEST UNIT READY"); | 2152 | "TEST UNIT READY"); |
2124 | break; | 2153 | break; |
2125 | 2154 | ||
2126 | /* Although optional, this command is used by MS-Windows. We | 2155 | /* |
2127 | * support a minimal version: BytChk must be 0. */ | 2156 | * Although optional, this command is used by MS-Windows. We |
2157 | * support a minimal version: BytChk must be 0. | ||
2158 | */ | ||
2128 | case VERIFY: | 2159 | case VERIFY: |
2129 | common->data_size_from_cmnd = 0; | 2160 | common->data_size_from_cmnd = 0; |
2130 | reply = check_command(common, 10, DATA_DIR_NONE, | 2161 | reply = check_command(common, 10, DATA_DIR_NONE, |
@@ -2164,10 +2195,12 @@ static int do_scsi_command(struct fsg_common *common) | |||
2164 | reply = do_write(common); | 2195 | reply = do_write(common); |
2165 | break; | 2196 | break; |
2166 | 2197 | ||
2167 | /* Some mandatory commands that we recognize but don't implement. | 2198 | /* |
2199 | * Some mandatory commands that we recognize but don't implement. | ||
2168 | * They don't mean much in this setting. It's left as an exercise | 2200 | * They don't mean much in this setting. It's left as an exercise |
2169 | * for anyone interested to implement RESERVE and RELEASE in terms | 2201 | * for anyone interested to implement RESERVE and RELEASE in terms |
2170 | * of Posix locks. */ | 2202 | * of Posix locks. |
2203 | */ | ||
2171 | case FORMAT_UNIT: | 2204 | case FORMAT_UNIT: |
2172 | case RELEASE: | 2205 | case RELEASE: |
2173 | case RESERVE: | 2206 | case RESERVE: |
@@ -2195,7 +2228,7 @@ unknown_cmnd: | |||
2195 | if (reply == -EINVAL) | 2228 | if (reply == -EINVAL) |
2196 | reply = 0; /* Error reply length */ | 2229 | reply = 0; /* Error reply length */ |
2197 | if (reply >= 0 && common->data_dir == DATA_DIR_TO_HOST) { | 2230 | if (reply >= 0 && common->data_dir == DATA_DIR_TO_HOST) { |
2198 | reply = min((u32) reply, common->data_size_from_cmnd); | 2231 | reply = min((u32)reply, common->data_size_from_cmnd); |
2199 | bh->inreq->length = reply; | 2232 | bh->inreq->length = reply; |
2200 | bh->state = BUF_STATE_FULL; | 2233 | bh->state = BUF_STATE_FULL; |
2201 | common->residue -= reply; | 2234 | common->residue -= reply; |
@@ -2225,7 +2258,8 @@ static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh) | |||
2225 | req->actual, | 2258 | req->actual, |
2226 | le32_to_cpu(cbw->Signature)); | 2259 | le32_to_cpu(cbw->Signature)); |
2227 | 2260 | ||
2228 | /* The Bulk-only spec says we MUST stall the IN endpoint | 2261 | /* |
2262 | * The Bulk-only spec says we MUST stall the IN endpoint | ||
2229 | * (6.6.1), so it's unavoidable. It also says we must | 2263 | * (6.6.1), so it's unavoidable. It also says we must |
2230 | * retain this state until the next reset, but there's | 2264 | * retain this state until the next reset, but there's |
2231 | * no way to tell the controller driver it should ignore | 2265 | * no way to tell the controller driver it should ignore |
@@ -2233,7 +2267,8 @@ static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh) | |||
2233 | * | 2267 | * |
2234 | * We aren't required to halt the OUT endpoint; instead | 2268 | * We aren't required to halt the OUT endpoint; instead |
2235 | * we can simply accept and discard any data received | 2269 | * we can simply accept and discard any data received |
2236 | * until the next reset. */ | 2270 | * until the next reset. |
2271 | */ | ||
2237 | wedge_bulk_in_endpoint(fsg); | 2272 | wedge_bulk_in_endpoint(fsg); |
2238 | set_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags); | 2273 | set_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags); |
2239 | return -EINVAL; | 2274 | return -EINVAL; |
@@ -2246,8 +2281,10 @@ static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh) | |||
2246 | "cmdlen %u\n", | 2281 | "cmdlen %u\n", |
2247 | cbw->Lun, cbw->Flags, cbw->Length); | 2282 | cbw->Lun, cbw->Flags, cbw->Length); |
2248 | 2283 | ||
2249 | /* We can do anything we want here, so let's stall the | 2284 | /* |
2250 | * bulk pipes if we are allowed to. */ | 2285 | * We can do anything we want here, so let's stall the |
2286 | * bulk pipes if we are allowed to. | ||
2287 | */ | ||
2251 | if (common->can_stall) { | 2288 | if (common->can_stall) { |
2252 | fsg_set_halt(fsg, fsg->bulk_out); | 2289 | fsg_set_halt(fsg, fsg->bulk_out); |
2253 | halt_bulk_in_endpoint(fsg); | 2290 | halt_bulk_in_endpoint(fsg); |
@@ -2270,7 +2307,6 @@ static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh) | |||
2270 | return 0; | 2307 | return 0; |
2271 | } | 2308 | } |
2272 | 2309 | ||
2273 | |||
2274 | static int get_next_command(struct fsg_common *common) | 2310 | static int get_next_command(struct fsg_common *common) |
2275 | { | 2311 | { |
2276 | struct fsg_buffhd *bh; | 2312 | struct fsg_buffhd *bh; |
@@ -2291,9 +2327,11 @@ static int get_next_command(struct fsg_common *common) | |||
2291 | /* Don't know what to do if common->fsg is NULL */ | 2327 | /* Don't know what to do if common->fsg is NULL */ |
2292 | return -EIO; | 2328 | return -EIO; |
2293 | 2329 | ||
2294 | /* We will drain the buffer in software, which means we | 2330 | /* |
2331 | * We will drain the buffer in software, which means we | ||
2295 | * can reuse it for the next filling. No need to advance | 2332 | * can reuse it for the next filling. No need to advance |
2296 | * next_buffhd_to_fill. */ | 2333 | * next_buffhd_to_fill. |
2334 | */ | ||
2297 | 2335 | ||
2298 | /* Wait for the CBW to arrive */ | 2336 | /* Wait for the CBW to arrive */ |
2299 | while (bh->state != BUF_STATE_FULL) { | 2337 | while (bh->state != BUF_STATE_FULL) { |
@@ -2424,7 +2462,6 @@ reset: | |||
2424 | 2462 | ||
2425 | /****************************** ALT CONFIGS ******************************/ | 2463 | /****************************** ALT CONFIGS ******************************/ |
2426 | 2464 | ||
2427 | |||
2428 | static int fsg_set_alt(struct usb_function *f, unsigned intf, unsigned alt) | 2465 | static int fsg_set_alt(struct usb_function *f, unsigned intf, unsigned alt) |
2429 | { | 2466 | { |
2430 | struct fsg_dev *fsg = fsg_from_func(f); | 2467 | struct fsg_dev *fsg = fsg_from_func(f); |
@@ -2452,8 +2489,10 @@ static void handle_exception(struct fsg_common *common) | |||
2452 | struct fsg_lun *curlun; | 2489 | struct fsg_lun *curlun; |
2453 | unsigned int exception_req_tag; | 2490 | unsigned int exception_req_tag; |
2454 | 2491 | ||
2455 | /* Clear the existing signals. Anything but SIGUSR1 is converted | 2492 | /* |
2456 | * into a high-priority EXIT exception. */ | 2493 | * Clear the existing signals. Anything but SIGUSR1 is converted |
2494 | * into a high-priority EXIT exception. | ||
2495 | */ | ||
2457 | for (;;) { | 2496 | for (;;) { |
2458 | int sig = | 2497 | int sig = |
2459 | dequeue_signal_lock(current, ¤t->blocked, &info); | 2498 | dequeue_signal_lock(current, ¤t->blocked, &info); |
@@ -2497,8 +2536,10 @@ static void handle_exception(struct fsg_common *common) | |||
2497 | usb_ep_fifo_flush(common->fsg->bulk_out); | 2536 | usb_ep_fifo_flush(common->fsg->bulk_out); |
2498 | } | 2537 | } |
2499 | 2538 | ||
2500 | /* Reset the I/O buffer states and pointers, the SCSI | 2539 | /* |
2501 | * state, and the exception. Then invoke the handler. */ | 2540 | * Reset the I/O buffer states and pointers, the SCSI |
2541 | * state, and the exception. Then invoke the handler. | ||
2542 | */ | ||
2502 | spin_lock_irq(&common->lock); | 2543 | spin_lock_irq(&common->lock); |
2503 | 2544 | ||
2504 | for (i = 0; i < FSG_NUM_BUFFERS; ++i) { | 2545 | for (i = 0; i < FSG_NUM_BUFFERS; ++i) { |
@@ -2536,9 +2577,11 @@ static void handle_exception(struct fsg_common *common) | |||
2536 | break; | 2577 | break; |
2537 | 2578 | ||
2538 | case FSG_STATE_RESET: | 2579 | case FSG_STATE_RESET: |
2539 | /* In case we were forced against our will to halt a | 2580 | /* |
2581 | * In case we were forced against our will to halt a | ||
2540 | * bulk endpoint, clear the halt now. (The SuperH UDC | 2582 | * bulk endpoint, clear the halt now. (The SuperH UDC |
2541 | * requires this.) */ | 2583 | * requires this.) |
2584 | */ | ||
2542 | if (!fsg_is_set(common)) | 2585 | if (!fsg_is_set(common)) |
2543 | break; | 2586 | break; |
2544 | if (test_and_clear_bit(IGNORE_BULK_OUT, | 2587 | if (test_and_clear_bit(IGNORE_BULK_OUT, |
@@ -2548,9 +2591,11 @@ static void handle_exception(struct fsg_common *common) | |||
2548 | if (common->ep0_req_tag == exception_req_tag) | 2591 | if (common->ep0_req_tag == exception_req_tag) |
2549 | ep0_queue(common); /* Complete the status stage */ | 2592 | ep0_queue(common); /* Complete the status stage */ |
2550 | 2593 | ||
2551 | /* Technically this should go here, but it would only be | 2594 | /* |
2595 | * Technically this should go here, but it would only be | ||
2552 | * a waste of time. Ditto for the INTERFACE_CHANGE and | 2596 | * a waste of time. Ditto for the INTERFACE_CHANGE and |
2553 | * CONFIG_CHANGE cases. */ | 2597 | * CONFIG_CHANGE cases. |
2598 | */ | ||
2554 | /* for (i = 0; i < common->nluns; ++i) */ | 2599 | /* for (i = 0; i < common->nluns; ++i) */ |
2555 | /* common->luns[i].unit_attention_data = */ | 2600 | /* common->luns[i].unit_attention_data = */ |
2556 | /* SS_RESET_OCCURRED; */ | 2601 | /* SS_RESET_OCCURRED; */ |
@@ -2585,8 +2630,10 @@ static int fsg_main_thread(void *common_) | |||
2585 | { | 2630 | { |
2586 | struct fsg_common *common = common_; | 2631 | struct fsg_common *common = common_; |
2587 | 2632 | ||
2588 | /* Allow the thread to be killed by a signal, but set the signal mask | 2633 | /* |
2589 | * to block everything but INT, TERM, KILL, and USR1. */ | 2634 | * Allow the thread to be killed by a signal, but set the signal mask |
2635 | * to block everything but INT, TERM, KILL, and USR1. | ||
2636 | */ | ||
2590 | allow_signal(SIGINT); | 2637 | allow_signal(SIGINT); |
2591 | allow_signal(SIGTERM); | 2638 | allow_signal(SIGTERM); |
2592 | allow_signal(SIGKILL); | 2639 | allow_signal(SIGKILL); |
@@ -2595,9 +2642,11 @@ static int fsg_main_thread(void *common_) | |||
2595 | /* Allow the thread to be frozen */ | 2642 | /* Allow the thread to be frozen */ |
2596 | set_freezable(); | 2643 | set_freezable(); |
2597 | 2644 | ||
2598 | /* Arrange for userspace references to be interpreted as kernel | 2645 | /* |
2646 | * Arrange for userspace references to be interpreted as kernel | ||
2599 | * pointers. That way we can pass a kernel pointer to a routine | 2647 | * pointers. That way we can pass a kernel pointer to a routine |
2600 | * that expects a __user pointer and it will work okay. */ | 2648 | * that expects a __user pointer and it will work okay. |
2649 | */ | ||
2601 | set_fs(get_ds()); | 2650 | set_fs(get_ds()); |
2602 | 2651 | ||
2603 | /* The main loop */ | 2652 | /* The main loop */ |
@@ -2689,7 +2738,6 @@ static inline void fsg_common_put(struct fsg_common *common) | |||
2689 | kref_put(&common->ref, fsg_common_release); | 2738 | kref_put(&common->ref, fsg_common_release); |
2690 | } | 2739 | } |
2691 | 2740 | ||
2692 | |||
2693 | static struct fsg_common *fsg_common_init(struct fsg_common *common, | 2741 | static struct fsg_common *fsg_common_init(struct fsg_common *common, |
2694 | struct usb_composite_dev *cdev, | 2742 | struct usb_composite_dev *cdev, |
2695 | struct fsg_config *cfg) | 2743 | struct fsg_config *cfg) |
@@ -2735,8 +2783,10 @@ static struct fsg_common *fsg_common_init(struct fsg_common *common, | |||
2735 | fsg_intf_desc.iInterface = rc; | 2783 | fsg_intf_desc.iInterface = rc; |
2736 | } | 2784 | } |
2737 | 2785 | ||
2738 | /* Create the LUNs, open their backing files, and register the | 2786 | /* |
2739 | * LUN devices in sysfs. */ | 2787 | * Create the LUNs, open their backing files, and register the |
2788 | * LUN devices in sysfs. | ||
2789 | */ | ||
2740 | curlun = kzalloc(nluns * sizeof *curlun, GFP_KERNEL); | 2790 | curlun = kzalloc(nluns * sizeof *curlun, GFP_KERNEL); |
2741 | if (unlikely(!curlun)) { | 2791 | if (unlikely(!curlun)) { |
2742 | rc = -ENOMEM; | 2792 | rc = -ENOMEM; |
@@ -2790,7 +2840,6 @@ static struct fsg_common *fsg_common_init(struct fsg_common *common, | |||
2790 | } | 2840 | } |
2791 | common->nluns = nluns; | 2841 | common->nluns = nluns; |
2792 | 2842 | ||
2793 | |||
2794 | /* Data buffers cyclic list */ | 2843 | /* Data buffers cyclic list */ |
2795 | bh = common->buffhds; | 2844 | bh = common->buffhds; |
2796 | i = FSG_NUM_BUFFERS; | 2845 | i = FSG_NUM_BUFFERS; |
@@ -2807,7 +2856,6 @@ buffhds_first_it: | |||
2807 | } while (--i); | 2856 | } while (--i); |
2808 | bh->next = common->buffhds; | 2857 | bh->next = common->buffhds; |
2809 | 2858 | ||
2810 | |||
2811 | /* Prepare inquiryString */ | 2859 | /* Prepare inquiryString */ |
2812 | if (cfg->release != 0xffff) { | 2860 | if (cfg->release != 0xffff) { |
2813 | i = cfg->release; | 2861 | i = cfg->release; |
@@ -2829,19 +2877,17 @@ buffhds_first_it: | |||
2829 | : "File-CD Gadget"), | 2877 | : "File-CD Gadget"), |
2830 | i); | 2878 | i); |
2831 | 2879 | ||
2832 | 2880 | /* | |
2833 | /* Some peripheral controllers are known not to be able to | 2881 | * Some peripheral controllers are known not to be able to |
2834 | * halt bulk endpoints correctly. If one of them is present, | 2882 | * halt bulk endpoints correctly. If one of them is present, |
2835 | * disable stalls. | 2883 | * disable stalls. |
2836 | */ | 2884 | */ |
2837 | common->can_stall = cfg->can_stall && | 2885 | common->can_stall = cfg->can_stall && |
2838 | !(gadget_is_at91(common->gadget)); | 2886 | !(gadget_is_at91(common->gadget)); |
2839 | 2887 | ||
2840 | |||
2841 | spin_lock_init(&common->lock); | 2888 | spin_lock_init(&common->lock); |
2842 | kref_init(&common->ref); | 2889 | kref_init(&common->ref); |
2843 | 2890 | ||
2844 | |||
2845 | /* Tell the thread to start working */ | 2891 | /* Tell the thread to start working */ |
2846 | common->thread_task = | 2892 | common->thread_task = |
2847 | kthread_create(fsg_main_thread, common, | 2893 | kthread_create(fsg_main_thread, common, |
@@ -2853,7 +2899,6 @@ buffhds_first_it: | |||
2853 | init_completion(&common->thread_notifier); | 2899 | init_completion(&common->thread_notifier); |
2854 | init_waitqueue_head(&common->fsg_wait); | 2900 | init_waitqueue_head(&common->fsg_wait); |
2855 | 2901 | ||
2856 | |||
2857 | /* Information */ | 2902 | /* Information */ |
2858 | INFO(common, FSG_DRIVER_DESC ", version: " FSG_DRIVER_VERSION "\n"); | 2903 | INFO(common, FSG_DRIVER_DESC ", version: " FSG_DRIVER_VERSION "\n"); |
2859 | INFO(common, "Number of LUNs=%d\n", common->nluns); | 2904 | INFO(common, "Number of LUNs=%d\n", common->nluns); |
@@ -2886,18 +2931,15 @@ buffhds_first_it: | |||
2886 | 2931 | ||
2887 | return common; | 2932 | return common; |
2888 | 2933 | ||
2889 | |||
2890 | error_luns: | 2934 | error_luns: |
2891 | common->nluns = i + 1; | 2935 | common->nluns = i + 1; |
2892 | error_release: | 2936 | error_release: |
2893 | common->state = FSG_STATE_TERMINATED; /* The thread is dead */ | 2937 | common->state = FSG_STATE_TERMINATED; /* The thread is dead */ |
2894 | /* Call fsg_common_release() directly, ref might be not | 2938 | /* Call fsg_common_release() directly, ref might be not initialised. */ |
2895 | * initialised */ | ||
2896 | fsg_common_release(&common->ref); | 2939 | fsg_common_release(&common->ref); |
2897 | return ERR_PTR(rc); | 2940 | return ERR_PTR(rc); |
2898 | } | 2941 | } |
2899 | 2942 | ||
2900 | |||
2901 | static void fsg_common_release(struct kref *ref) | 2943 | static void fsg_common_release(struct kref *ref) |
2902 | { | 2944 | { |
2903 | struct fsg_common *common = container_of(ref, struct fsg_common, ref); | 2945 | struct fsg_common *common = container_of(ref, struct fsg_common, ref); |
@@ -2939,7 +2981,6 @@ static void fsg_common_release(struct kref *ref) | |||
2939 | 2981 | ||
2940 | /*-------------------------------------------------------------------------*/ | 2982 | /*-------------------------------------------------------------------------*/ |
2941 | 2983 | ||
2942 | |||
2943 | static void fsg_unbind(struct usb_configuration *c, struct usb_function *f) | 2984 | static void fsg_unbind(struct usb_configuration *c, struct usb_function *f) |
2944 | { | 2985 | { |
2945 | struct fsg_dev *fsg = fsg_from_func(f); | 2986 | struct fsg_dev *fsg = fsg_from_func(f); |
@@ -2959,7 +3000,6 @@ static void fsg_unbind(struct usb_configuration *c, struct usb_function *f) | |||
2959 | kfree(fsg); | 3000 | kfree(fsg); |
2960 | } | 3001 | } |
2961 | 3002 | ||
2962 | |||
2963 | static int fsg_bind(struct usb_configuration *c, struct usb_function *f) | 3003 | static int fsg_bind(struct usb_configuration *c, struct usb_function *f) |
2964 | { | 3004 | { |
2965 | struct fsg_dev *fsg = fsg_from_func(f); | 3005 | struct fsg_dev *fsg = fsg_from_func(f); |
@@ -3042,11 +3082,13 @@ static int fsg_bind_config(struct usb_composite_dev *cdev, | |||
3042 | fsg->function.disable = fsg_disable; | 3082 | fsg->function.disable = fsg_disable; |
3043 | 3083 | ||
3044 | fsg->common = common; | 3084 | fsg->common = common; |
3045 | /* Our caller holds a reference to common structure so we | 3085 | /* |
3086 | * Our caller holds a reference to common structure so we | ||
3046 | * don't have to be worry about it being freed until we return | 3087 | * don't have to be worry about it being freed until we return |
3047 | * from this function. So instead of incrementing counter now | 3088 | * from this function. So instead of incrementing counter now |
3048 | * and decrement in error recovery we increment it only when | 3089 | * and decrement in error recovery we increment it only when |
3049 | * call to usb_add_function() was successful. */ | 3090 | * call to usb_add_function() was successful. |
3091 | */ | ||
3050 | 3092 | ||
3051 | rc = usb_add_function(c, &fsg->function); | 3093 | rc = usb_add_function(c, &fsg->function); |
3052 | if (unlikely(rc)) | 3094 | if (unlikely(rc)) |
@@ -3057,8 +3099,7 @@ static int fsg_bind_config(struct usb_composite_dev *cdev, | |||
3057 | } | 3099 | } |
3058 | 3100 | ||
3059 | static inline int __deprecated __maybe_unused | 3101 | static inline int __deprecated __maybe_unused |
3060 | fsg_add(struct usb_composite_dev *cdev, | 3102 | fsg_add(struct usb_composite_dev *cdev, struct usb_configuration *c, |
3061 | struct usb_configuration *c, | ||
3062 | struct fsg_common *common) | 3103 | struct fsg_common *common) |
3063 | { | 3104 | { |
3064 | return fsg_bind_config(cdev, c, common); | 3105 | return fsg_bind_config(cdev, c, common); |
@@ -3067,7 +3108,6 @@ fsg_add(struct usb_composite_dev *cdev, | |||
3067 | 3108 | ||
3068 | /************************* Module parameters *************************/ | 3109 | /************************* Module parameters *************************/ |
3069 | 3110 | ||
3070 | |||
3071 | struct fsg_module_parameters { | 3111 | struct fsg_module_parameters { |
3072 | char *file[FSG_MAX_LUNS]; | 3112 | char *file[FSG_MAX_LUNS]; |
3073 | int ro[FSG_MAX_LUNS]; | 3113 | int ro[FSG_MAX_LUNS]; |
@@ -3081,7 +3121,6 @@ struct fsg_module_parameters { | |||
3081 | int stall; /* can_stall */ | 3121 | int stall; /* can_stall */ |
3082 | }; | 3122 | }; |
3083 | 3123 | ||
3084 | |||
3085 | #define _FSG_MODULE_PARAM_ARRAY(prefix, params, name, type, desc) \ | 3124 | #define _FSG_MODULE_PARAM_ARRAY(prefix, params, name, type, desc) \ |
3086 | module_param_array_named(prefix ## name, params.name, type, \ | 3125 | module_param_array_named(prefix ## name, params.name, type, \ |
3087 | &prefix ## params.name ## _count, \ | 3126 | &prefix ## params.name ## _count, \ |
@@ -3109,7 +3148,6 @@ struct fsg_module_parameters { | |||
3109 | _FSG_MODULE_PARAM(prefix, params, stall, bool, \ | 3148 | _FSG_MODULE_PARAM(prefix, params, stall, bool, \ |
3110 | "false to prevent bulk stalls") | 3149 | "false to prevent bulk stalls") |
3111 | 3150 | ||
3112 | |||
3113 | static void | 3151 | static void |
3114 | fsg_config_from_params(struct fsg_config *cfg, | 3152 | fsg_config_from_params(struct fsg_config *cfg, |
3115 | const struct fsg_module_parameters *params) | 3153 | const struct fsg_module_parameters *params) |
diff --git a/drivers/usb/gadget/mass_storage.c b/drivers/usb/gadget/mass_storage.c index 0769179dbdb0..01822422c3e8 100644 --- a/drivers/usb/gadget/mass_storage.c +++ b/drivers/usb/gadget/mass_storage.c | |||
@@ -102,7 +102,7 @@ static struct fsg_module_parameters mod_data = { | |||
102 | }; | 102 | }; |
103 | FSG_MODULE_PARAMETERS(/* no prefix */, mod_data); | 103 | FSG_MODULE_PARAMETERS(/* no prefix */, mod_data); |
104 | 104 | ||
105 | static unsigned long msg_registered = 0; | 105 | static unsigned long msg_registered; |
106 | static void msg_cleanup(void); | 106 | static void msg_cleanup(void); |
107 | 107 | ||
108 | static int msg_thread_exits(struct fsg_common *common) | 108 | static int msg_thread_exits(struct fsg_common *common) |