aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/renesas_usbhs
diff options
context:
space:
mode:
authorKuninori Morimoto <kuninori.morimoto.gx@renesas.com>2011-10-31 03:46:50 -0400
committerFelipe Balbi <balbi@ti.com>2011-12-12 04:45:01 -0500
commitee8a0bf5a775098b1140195b6bfacb4813166e5f (patch)
tree18853a11061f13f4aeabbbaeb5ad88470fae5307 /drivers/usb/renesas_usbhs
parent1ab6f257e12a89f62f58fcef9f7b85badce412bc (diff)
usb: gadget: renesas_usbhs: cleanup complicated ureq alloc/free
DCP data/status stage needs ureq to usbhs_pkt_push(), but sometimes, there is no data stage. In that case, allocated ureq was not freed, Current ureq alloc/free pair were difficult to understand. This patch removed unnecessary/un-understandable ureq alloc from usbhsh_urb_enqueue(), and create simpler alloc/free pair. Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> Signed-off-by: Felipe Balbi <balbi@ti.com>
Diffstat (limited to 'drivers/usb/renesas_usbhs')
-rw-r--r--drivers/usb/renesas_usbhs/mod_host.c107
1 files changed, 56 insertions, 51 deletions
diff --git a/drivers/usb/renesas_usbhs/mod_host.c b/drivers/usb/renesas_usbhs/mod_host.c
index c453b6c215a7..478366b571ef 100644
--- a/drivers/usb/renesas_usbhs/mod_host.c
+++ b/drivers/usb/renesas_usbhs/mod_host.c
@@ -503,11 +503,12 @@ static void usbhsh_queue_done(struct usbhs_priv *priv, struct usbhs_pkt *pkt)
503 503
504static int usbhsh_queue_push(struct usb_hcd *hcd, 504static int usbhsh_queue_push(struct usb_hcd *hcd,
505 struct usbhs_pipe *pipe, 505 struct usbhs_pipe *pipe,
506 struct urb *urb) 506 struct urb *urb,
507 gfp_t mem_flags)
507{ 508{
508 struct usbhsh_request *ureq = usbhsh_urb_to_ureq(urb); 509 struct usbhsh_hpriv *hpriv = usbhsh_hcd_to_hpriv(hcd);
509 struct usbhs_pkt *pkt = &ureq->pkt;
510 struct device *dev = usbhsh_hcd_to_dev(hcd); 510 struct device *dev = usbhsh_hcd_to_dev(hcd);
511 struct usbhsh_request *ureq;
511 void *buf; 512 void *buf;
512 int len; 513 int len;
513 514
@@ -516,6 +517,14 @@ static int usbhsh_queue_push(struct usb_hcd *hcd,
516 return -EIO; 517 return -EIO;
517 } 518 }
518 519
520 /* this ureq will be freed on usbhsh_queue_done() */
521 ureq = usbhsh_ureq_alloc(hpriv, urb, mem_flags);
522 if (unlikely(!ureq)) {
523 dev_err(dev, "ureq alloc fail\n");
524 return -ENOMEM;
525 }
526 usbhsh_urb_to_ureq(urb) = ureq;
527
519 if (usb_pipein(urb->pipe)) 528 if (usb_pipein(urb->pipe))
520 pipe->handler = &usbhs_fifo_pio_pop_handler; 529 pipe->handler = &usbhs_fifo_pio_pop_handler;
521 else 530 else
@@ -525,7 +534,7 @@ static int usbhsh_queue_push(struct usb_hcd *hcd,
525 len = urb->transfer_buffer_length - urb->actual_length; 534 len = urb->transfer_buffer_length - urb->actual_length;
526 535
527 dev_dbg(dev, "%s\n", __func__); 536 dev_dbg(dev, "%s\n", __func__);
528 usbhs_pkt_push(pipe, pkt, usbhsh_queue_done, 537 usbhs_pkt_push(pipe, &ureq->pkt, usbhsh_queue_done,
529 buf, len, (urb->transfer_flags & URB_ZERO_PACKET)); 538 buf, len, (urb->transfer_flags & URB_ZERO_PACKET));
530 usbhs_pkt_start(pipe); 539 usbhs_pkt_start(pipe);
531 540
@@ -605,72 +614,72 @@ static void usbhsh_data_stage_packet_done(struct usbhs_priv *priv,
605 usbhsh_urb_to_ureq(urb) = NULL; 614 usbhsh_urb_to_ureq(urb) = NULL;
606} 615}
607 616
608static void usbhsh_data_stage_packet_push(struct usbhsh_hpriv *hpriv, 617static int usbhsh_data_stage_packet_push(struct usbhsh_hpriv *hpriv,
609 struct urb *urb, 618 struct urb *urb,
610 struct usbhs_pipe *pipe) 619 struct usbhs_pipe *pipe,
620 gfp_t mem_flags)
621
611{ 622{
612 struct usbhsh_request *ureq; 623 struct usbhsh_request *ureq;
613 struct usbhs_pkt *pkt;
614 624
615 /* 625 /* this ureq will be freed on usbhsh_data_stage_packet_done() */
616 * FIXME 626 ureq = usbhsh_ureq_alloc(hpriv, urb, mem_flags);
617 * 627 if (unlikely(!ureq))
618 * data stage uses ureq which is connected to urb 628 return -ENOMEM;
619 * see usbhsh_urb_enqueue() :: alloc new request. 629 usbhsh_urb_to_ureq(urb) = ureq;
620 * it will be freed in usbhsh_data_stage_packet_done()
621 */
622 ureq = usbhsh_urb_to_ureq(urb);
623 pkt = &ureq->pkt;
624 630
625 if (usb_pipein(urb->pipe)) 631 if (usb_pipein(urb->pipe))
626 pipe->handler = &usbhs_dcp_data_stage_in_handler; 632 pipe->handler = &usbhs_dcp_data_stage_in_handler;
627 else 633 else
628 pipe->handler = &usbhs_dcp_data_stage_out_handler; 634 pipe->handler = &usbhs_dcp_data_stage_out_handler;
629 635
630 usbhs_pkt_push(pipe, pkt, 636 usbhs_pkt_push(pipe, &ureq->pkt,
631 usbhsh_data_stage_packet_done, 637 usbhsh_data_stage_packet_done,
632 urb->transfer_buffer, 638 urb->transfer_buffer,
633 urb->transfer_buffer_length, 639 urb->transfer_buffer_length,
634 (urb->transfer_flags & URB_ZERO_PACKET)); 640 (urb->transfer_flags & URB_ZERO_PACKET));
641
642 return 0;
635} 643}
636 644
637/* 645/*
638 * DCP status stage 646 * DCP status stage
639 */ 647 */
640static void usbhsh_status_stage_packet_push(struct usbhsh_hpriv *hpriv, 648static int usbhsh_status_stage_packet_push(struct usbhsh_hpriv *hpriv,
641 struct urb *urb, 649 struct urb *urb,
642 struct usbhs_pipe *pipe) 650 struct usbhs_pipe *pipe,
651 gfp_t mem_flags)
643{ 652{
644 struct usbhsh_request *ureq; 653 struct usbhsh_request *ureq;
645 struct usbhs_pkt *pkt;
646 654
647 /* 655 /* This ureq will be freed on usbhsh_queue_done() */
648 * FIXME 656 ureq = usbhsh_ureq_alloc(hpriv, urb, mem_flags);
649 * 657 if (unlikely(!ureq))
650 * status stage uses allocated ureq. 658 return -ENOMEM;
651 * it will be freed on usbhsh_queue_done() 659 usbhsh_urb_to_ureq(urb) = ureq;
652 */
653 ureq = usbhsh_ureq_alloc(hpriv, urb, GFP_KERNEL);
654 pkt = &ureq->pkt;
655 660
656 if (usb_pipein(urb->pipe)) 661 if (usb_pipein(urb->pipe))
657 pipe->handler = &usbhs_dcp_status_stage_in_handler; 662 pipe->handler = &usbhs_dcp_status_stage_in_handler;
658 else 663 else
659 pipe->handler = &usbhs_dcp_status_stage_out_handler; 664 pipe->handler = &usbhs_dcp_status_stage_out_handler;
660 665
661 usbhs_pkt_push(pipe, pkt, 666 usbhs_pkt_push(pipe, &ureq->pkt,
662 usbhsh_queue_done, 667 usbhsh_queue_done,
663 NULL, 668 NULL,
664 urb->transfer_buffer_length, 669 urb->transfer_buffer_length,
665 0); 670 0);
671
672 return 0;
666} 673}
667 674
668static int usbhsh_dcp_queue_push(struct usb_hcd *hcd, 675static int usbhsh_dcp_queue_push(struct usb_hcd *hcd,
669 struct usbhsh_hpriv *hpriv,
670 struct usbhs_pipe *pipe, 676 struct usbhs_pipe *pipe,
671 struct urb *urb) 677 struct urb *urb,
678 gfp_t mflags)
672{ 679{
680 struct usbhsh_hpriv *hpriv = usbhsh_hcd_to_hpriv(hcd);
673 struct device *dev = usbhsh_hcd_to_dev(hcd); 681 struct device *dev = usbhsh_hcd_to_dev(hcd);
682 int ret;
674 683
675 dev_dbg(dev, "%s\n", __func__); 684 dev_dbg(dev, "%s\n", __func__);
676 685
@@ -686,13 +695,22 @@ static int usbhsh_dcp_queue_push(struct usb_hcd *hcd,
686 * 695 *
687 * It is pushed only when urb has buffer. 696 * It is pushed only when urb has buffer.
688 */ 697 */
689 if (urb->transfer_buffer_length) 698 if (urb->transfer_buffer_length) {
690 usbhsh_data_stage_packet_push(hpriv, urb, pipe); 699 ret = usbhsh_data_stage_packet_push(hpriv, urb, pipe, mflags);
700 if (ret < 0) {
701 dev_err(dev, "data stage failed\n");
702 return ret;
703 }
704 }
691 705
692 /* 706 /*
693 * status stage 707 * status stage
694 */ 708 */
695 usbhsh_status_stage_packet_push(hpriv, urb, pipe); 709 ret = usbhsh_status_stage_packet_push(hpriv, urb, pipe, mflags);
710 if (ret < 0) {
711 dev_err(dev, "status stage failed\n");
712 return ret;
713 }
696 714
697 /* 715 /*
698 * start pushed packets 716 * start pushed packets
@@ -731,7 +749,6 @@ static int usbhsh_urb_enqueue(struct usb_hcd *hcd,
731 struct device *dev = usbhs_priv_to_dev(priv); 749 struct device *dev = usbhs_priv_to_dev(priv);
732 struct usb_device *usbv = usbhsh_urb_to_usbv(urb); 750 struct usb_device *usbv = usbhsh_urb_to_usbv(urb);
733 struct usb_host_endpoint *ep = urb->ep; 751 struct usb_host_endpoint *ep = urb->ep;
734 struct usbhsh_request *ureq;
735 struct usbhsh_device *udev, *new_udev = NULL; 752 struct usbhsh_device *udev, *new_udev = NULL;
736 struct usbhs_pipe *pipe; 753 struct usbhs_pipe *pipe;
737 struct usbhsh_ep *uep; 754 struct usbhsh_ep *uep;
@@ -770,27 +787,15 @@ static int usbhsh_urb_enqueue(struct usb_hcd *hcd,
770 pipe = usbhsh_uep_to_pipe(uep); 787 pipe = usbhsh_uep_to_pipe(uep);
771 788
772 /* 789 /*
773 * alloc new request
774 */
775 ureq = usbhsh_ureq_alloc(hpriv, urb, mem_flags);
776 if (unlikely(!ureq)) {
777 ret = -ENOMEM;
778 goto usbhsh_urb_enqueue_error_free_endpoint;
779 }
780 usbhsh_urb_to_ureq(urb) = ureq;
781
782 /*
783 * push packet 790 * push packet
784 */ 791 */
785 if (usb_pipecontrol(urb->pipe)) 792 if (usb_pipecontrol(urb->pipe))
786 usbhsh_dcp_queue_push(hcd, hpriv, pipe, urb); 793 ret = usbhsh_dcp_queue_push(hcd, pipe, urb, mem_flags);
787 else 794 else
788 usbhsh_queue_push(hcd, pipe, urb); 795 ret = usbhsh_queue_push(hcd, pipe, urb, mem_flags);
789 796
790 return 0; 797 return ret;
791 798
792usbhsh_urb_enqueue_error_free_endpoint:
793 usbhsh_endpoint_free(hpriv, ep);
794usbhsh_urb_enqueue_error_free_device: 799usbhsh_urb_enqueue_error_free_device:
795 if (new_udev) 800 if (new_udev)
796 usbhsh_device_free(hpriv, new_udev); 801 usbhsh_device_free(hpriv, new_udev);