aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Carpenter <dan.carpenter@oracle.com>2013-08-13 13:29:26 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-08-14 17:15:40 -0400
commit95b20b8b060ae9dbd4cf3de63c176935eef71837 (patch)
treeffae98f0b84ea7fdec43d9d0e39401eecbb269cd
parent5f1f7b110fc43b03af241302e99addca4c124638 (diff)
staging: ozwpan: Separate success & failure case for oz_hcd_pd_arrived()
This patch separates success & failure block along with fixing following issues:- 1. The way oz_hcd_pd_arrived() looks now it's easy to think we free "ep" but actually we do this spaghetti thing of setting it to NULL on success. 2. It is hard to read it because there are unlocks scattered throughout. 3. Currently we set "ep" to NULL on the success path and then test it and or free it. In current code you have to scroll to the start of the function to read code. Original patch was submitted by Dan here :- http://driverdev.linuxdriverproject.org/pipermail/driverdev-devel/2013-August/040113.html Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Rupesh Gujare <rupesh.gujare@atmel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/staging/ozwpan/ozhcd.c54
1 files changed, 27 insertions, 27 deletions
diff --git a/drivers/staging/ozwpan/ozhcd.c b/drivers/staging/ozwpan/ozhcd.c
index 0b21c9f4d2e3..4cd08daf5111 100644
--- a/drivers/staging/ozwpan/ozhcd.c
+++ b/drivers/staging/ozwpan/ozhcd.c
@@ -668,50 +668,50 @@ struct oz_port *oz_hcd_pd_arrived(void *hpd)
668 struct oz_endpoint *ep; 668 struct oz_endpoint *ep;
669 669
670 ozhcd = oz_hcd_claim(); 670 ozhcd = oz_hcd_claim();
671 if (ozhcd == NULL) 671 if (!ozhcd)
672 return NULL; 672 return NULL;
673 /* Allocate an endpoint object in advance (before holding hcd lock) to 673 /* Allocate an endpoint object in advance (before holding hcd lock) to
674 * use for out endpoint 0. 674 * use for out endpoint 0.
675 */ 675 */
676 ep = oz_ep_alloc(0, GFP_ATOMIC); 676 ep = oz_ep_alloc(0, GFP_ATOMIC);
677 if (!ep)
678 goto err_put;
679
677 spin_lock_bh(&ozhcd->hcd_lock); 680 spin_lock_bh(&ozhcd->hcd_lock);
678 if (ozhcd->conn_port >= 0) { 681 if (ozhcd->conn_port >= 0)
679 spin_unlock_bh(&ozhcd->hcd_lock); 682 goto err_unlock;
680 oz_dbg(ON, "conn_port >= 0\n"); 683
681 goto out;
682 }
683 for (i = 0; i < OZ_NB_PORTS; i++) { 684 for (i = 0; i < OZ_NB_PORTS; i++) {
684 struct oz_port *port = &ozhcd->ports[i]; 685 struct oz_port *port = &ozhcd->ports[i];
686
685 spin_lock(&port->port_lock); 687 spin_lock(&port->port_lock);
686 if ((port->flags & OZ_PORT_F_PRESENT) == 0) { 688 if (!(port->flags & OZ_PORT_F_PRESENT)) {
687 oz_acquire_port(port, hpd); 689 oz_acquire_port(port, hpd);
688 spin_unlock(&port->port_lock); 690 spin_unlock(&port->port_lock);
689 break; 691 break;
690 } 692 }
691 spin_unlock(&port->port_lock); 693 spin_unlock(&port->port_lock);
692 } 694 }
693 if (i < OZ_NB_PORTS) { 695 if (i == OZ_NB_PORTS)
694 oz_dbg(ON, "Setting conn_port = %d\n", i); 696 goto err_unlock;
695 ozhcd->conn_port = i; 697
696 /* Attach out endpoint 0. 698 ozhcd->conn_port = i;
697 */ 699 hport = &ozhcd->ports[i];
698 ozhcd->ports[i].out_ep[0] = ep; 700 hport->out_ep[0] = ep;
699 ep = NULL; 701 spin_unlock_bh(&ozhcd->hcd_lock);
700 hport = &ozhcd->ports[i]; 702 if (ozhcd->flags & OZ_HDC_F_SUSPENDED)
701 spin_unlock_bh(&ozhcd->hcd_lock); 703 usb_hcd_resume_root_hub(ozhcd->hcd);
702 if (ozhcd->flags & OZ_HDC_F_SUSPENDED) { 704 usb_hcd_poll_rh_status(ozhcd->hcd);
703 oz_dbg(ON, "Resuming root hub\n");
704 usb_hcd_resume_root_hub(ozhcd->hcd);
705 }
706 usb_hcd_poll_rh_status(ozhcd->hcd);
707 } else {
708 spin_unlock_bh(&ozhcd->hcd_lock);
709 }
710out:
711 if (ep) /* ep is non-null if not used. */
712 oz_ep_free(NULL, ep);
713 oz_hcd_put(ozhcd); 705 oz_hcd_put(ozhcd);
706
714 return hport; 707 return hport;
708
709err_unlock:
710 spin_unlock_bh(&ozhcd->hcd_lock);
711 oz_ep_free(NULL, ep);
712err_put:
713 oz_hcd_put(ozhcd);
714 return NULL;
715} 715}
716 716
717/*------------------------------------------------------------------------------ 717/*------------------------------------------------------------------------------