[PATCH 06/11] usb: gadget: udc: omap: simplify phy checks

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



transceiver is either NULL or a valid pointer. It is never
left containing -ve error value. Simplify error checks based on this.

Moreover, its OK to call phy APIs with NULL phy pointer.

Signed-off-by: Mian Yousaf Kaukab <yousaf.kaukab@xxxxxxxxx>
---
 drivers/usb/gadget/udc/omap_udc.c | 47 +++++++++++++++++----------------------
 1 file changed, 21 insertions(+), 26 deletions(-)

diff --git a/drivers/usb/gadget/udc/omap_udc.c b/drivers/usb/gadget/udc/omap_udc.c
index e2fcdb8..9c48694 100644
--- a/drivers/usb/gadget/udc/omap_udc.c
+++ b/drivers/usb/gadget/udc/omap_udc.c
@@ -1156,7 +1156,7 @@ static int omap_wakeup(struct usb_gadget *gadget)
 
 	/* NOTE:  non-OTG systems may use SRP TOO... */
 	} else if (!(udc->devstat & UDC_ATT)) {
-		if (!IS_ERR_OR_NULL(udc->transceiver))
+		if (udc->transceiver)
 			retval = otg_start_srp(udc->transceiver->otg);
 	}
 	spin_unlock_irqrestore(&udc->lock, flags);
@@ -1289,9 +1289,8 @@ static int omap_vbus_draw(struct usb_gadget *gadget, unsigned mA)
 	struct omap_udc	*udc;
 
 	udc = container_of(gadget, struct omap_udc, gadget);
-	if (!IS_ERR_OR_NULL(udc->transceiver))
-		return usb_phy_set_power(udc->transceiver, mA);
-	return -EOPNOTSUPP;
+
+	return usb_phy_set_power(udc->transceiver, mA);
 }
 
 static int omap_pullup(struct usb_gadget *gadget, int is_on)
@@ -1739,12 +1738,12 @@ static void devstate_irq(struct omap_udc *udc, u16 irq_src)
 			if (devstat & UDC_ATT) {
 				udc->gadget.speed = USB_SPEED_FULL;
 				VDBG("connect\n");
-				if (IS_ERR_OR_NULL(udc->transceiver))
+				if (!udc->transceiver)
 					pullup_enable(udc);
 				/* if (driver->connect) call it */
 			} else if (udc->gadget.speed != USB_SPEED_UNKNOWN) {
 				udc->gadget.speed = USB_SPEED_UNKNOWN;
-				if (IS_ERR_OR_NULL(udc->transceiver))
+				if (!udc->transceiver)
 					pullup_disable(udc);
 				DBG("disconnect, gadget %s\n",
 					udc->driver->driver.name);
@@ -1784,14 +1783,10 @@ static void devstate_irq(struct omap_udc *udc, u16 irq_src)
 					udc->driver->suspend(&udc->gadget);
 					spin_lock(&udc->lock);
 				}
-				if (!IS_ERR_OR_NULL(udc->transceiver))
-					usb_phy_set_suspend(
-							udc->transceiver, 1);
+				usb_phy_set_suspend(udc->transceiver, 1);
 			} else {
 				VDBG("resume\n");
-				if (!IS_ERR_OR_NULL(udc->transceiver))
-					usb_phy_set_suspend(
-							udc->transceiver, 0);
+				usb_phy_set_suspend(udc->transceiver, 0);
 				if (udc->gadget.speed == USB_SPEED_FULL
 						&& udc->driver->resume) {
 					spin_unlock(&udc->lock);
@@ -2074,7 +2069,7 @@ static int omap_udc_start(struct usb_gadget *g,
 	omap_writew(UDC_IRQ_SRC_MASK, UDC_IRQ_SRC);
 
 	/* connect to bus through transceiver */
-	if (!IS_ERR_OR_NULL(udc->transceiver)) {
+	if (udc->transceiver) {
 		status = otg_set_peripheral(udc->transceiver->otg,
 						&udc->gadget);
 		if (status < 0) {
@@ -2113,7 +2108,7 @@ static int omap_udc_stop(struct usb_gadget *g)
 	if (machine_without_vbus_sense())
 		omap_vbus_session(&udc->gadget, 0);
 
-	if (!IS_ERR_OR_NULL(udc->transceiver))
+	if (udc->transceiver)
 		(void) otg_set_peripheral(udc->transceiver->otg, NULL);
 	else
 		pullup_disable(udc);
@@ -2795,11 +2790,14 @@ static int omap_udc_probe(struct platform_device *pdev)
 		 * but not having one probably means no VBUS detection.
 		 */
 		xceiv = usb_get_phy(USB_PHY_TYPE_USB2);
-		if (!IS_ERR_OR_NULL(xceiv))
+		if (IS_ERR_OR_NULL(xceiv)) {
+			xceiv = NULL;
+			if (config->otg) {
+				DBG("OTG requires external transceiver!\n");
+				goto cleanup0;
+			}
+		} else {
 			type = xceiv->label;
-		else if (config->otg) {
-			DBG("OTG requires external transceiver!\n");
-			goto cleanup0;
 		}
 
 		hmc = HMC_1610;
@@ -2819,7 +2817,7 @@ static int omap_udc_probe(struct platform_device *pdev)
 		case 16:
 		case 19:
 		case 25:
-			if (IS_ERR_OR_NULL(xceiv)) {
+			if (!xceiv) {
 				DBG("external transceiver not registered!\n");
 				type = "unknown";
 			}
@@ -2850,7 +2848,6 @@ bad_on_1710:
 	if (status)
 		goto cleanup0;
 
-	xceiv = NULL;
 	/* "udc" is now valid */
 	pullup_disable(udc);
 #if	defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
@@ -2920,8 +2917,7 @@ cleanup1:
 	udc = NULL;
 
 cleanup0:
-	if (!IS_ERR_OR_NULL(xceiv))
-		usb_put_phy(xceiv);
+	usb_put_phy(xceiv);
 
 	if (cpu_is_omap16xx() || cpu_is_omap7xx()) {
 		clk_disable(hhc_clk);
@@ -2950,10 +2946,9 @@ static int omap_udc_remove(struct platform_device *pdev)
 	udc->done = &done;
 
 	pullup_disable(udc);
-	if (!IS_ERR_OR_NULL(udc->transceiver)) {
-		usb_put_phy(udc->transceiver);
-		udc->transceiver = NULL;
-	}
+	usb_put_phy(udc->transceiver);
+	udc->transceiver = NULL;
+
 	omap_writew(0, UDC_SYSCON1);
 
 	remove_proc_file();
-- 
2.3.3

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux