[PATCH] usb: dwc2: Remove unnecessary uphy and clk checkings

From: Sevak Arakelyan
Date: Fri Apr 21 2017 - 15:25:30 EST


hsotg->uphy and hsotg->clk will be set or NULL, but not ERRPTR.
So IS_ERR_OR_NULL() is not required at all.
NULL pointer argument is OK for "usb_phy_set_suspend", "otg_set_host",
"otg_set_peripheral", "clk_prepare_enable" and "clk_disable_unprepare"
functions. So remove unnecessary checkings.

Signed-off-by: Sevak Arakelyan <sevaka@xxxxxxxxxxxx>
---
drivers/usb/dwc2/core_intr.c | 3 +--
drivers/usb/dwc2/gadget.c | 8 +++-----
drivers/usb/dwc2/hcd.c | 22 ++++++++--------------
drivers/usb/dwc2/platform.c | 11 ++++-------
4 files changed, 16 insertions(+), 28 deletions(-)

diff --git a/drivers/usb/dwc2/core_intr.c b/drivers/usb/dwc2/core_intr.c
index b8bcb007c92a..b59bc58a5bfb 100644
--- a/drivers/usb/dwc2/core_intr.c
+++ b/drivers/usb/dwc2/core_intr.c
@@ -451,8 +451,7 @@ static void dwc2_handle_usb_suspend_intr(struct dwc2_hsotg *hsotg)
udelay(100);

/* Ask phy to be suspended */
- if (!IS_ERR_OR_NULL(hsotg->uphy))
- usb_phy_set_suspend(hsotg->uphy, true);
+ usb_phy_set_suspend(hsotg->uphy, true);
skip_power_saving:
/*
* Change to L2 (suspend) state before releasing
diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index 98a4a79e7f6e..634f9613bb56 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -4259,8 +4259,7 @@ static int dwc2_hsotg_udc_start(struct usb_gadget *gadget,
goto err;
}

- if (!IS_ERR_OR_NULL(hsotg->uphy))
- otg_set_peripheral(hsotg->uphy->otg, &hsotg->gadget);
+ otg_set_peripheral(hsotg->uphy->otg, &hsotg->gadget);

spin_lock_irqsave(&hsotg->lock, flags);
if (dwc2_hw_is_device(hsotg)) {
@@ -4312,8 +4311,7 @@ static int dwc2_hsotg_udc_stop(struct usb_gadget *gadget)

spin_unlock_irqrestore(&hsotg->lock, flags);

- if (!IS_ERR_OR_NULL(hsotg->uphy))
- otg_set_peripheral(hsotg->uphy->otg, NULL);
+ otg_set_peripheral(hsotg->uphy->otg, NULL);

if (hsotg->dr_mode == USB_DR_MODE_PERIPHERAL)
dwc2_lowlevel_hw_disable(hsotg);
@@ -4411,7 +4409,7 @@ static int dwc2_hsotg_vbus_draw(struct usb_gadget *gadget, unsigned int mA)
{
struct dwc2_hsotg *hsotg = to_hsotg(gadget);

- if (IS_ERR_OR_NULL(hsotg->uphy))
+ if (hsotg->uphy)
return -ENOTSUPP;
return usb_phy_set_power(hsotg->uphy, mA);
}
diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c
index f4ef159b538e..940d18dfde3e 100644
--- a/drivers/usb/dwc2/hcd.c
+++ b/drivers/usb/dwc2/hcd.c
@@ -4421,11 +4421,9 @@ static int _dwc2_hcd_suspend(struct usb_hcd *hcd)
}

/* Ask phy to be suspended */
- if (!IS_ERR_OR_NULL(hsotg->uphy)) {
- spin_unlock_irqrestore(&hsotg->lock, flags);
- usb_phy_set_suspend(hsotg->uphy, true);
- spin_lock_irqsave(&hsotg->lock, flags);
- }
+ spin_unlock_irqrestore(&hsotg->lock, flags);
+ usb_phy_set_suspend(hsotg->uphy, true);
+ spin_lock_irqsave(&hsotg->lock, flags);

/* After entering hibernation, hardware is no more accessible */
clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
@@ -4465,11 +4463,9 @@ static int _dwc2_hcd_resume(struct usb_hcd *hcd)
* This must not be spinlocked since duration
* of this call is unknown.
*/
- if (!IS_ERR_OR_NULL(hsotg->uphy)) {
- spin_unlock_irqrestore(&hsotg->lock, flags);
- usb_phy_set_suspend(hsotg->uphy, false);
- spin_lock_irqsave(&hsotg->lock, flags);
- }
+ spin_unlock_irqrestore(&hsotg->lock, flags);
+ usb_phy_set_suspend(hsotg->uphy, false);
+ spin_lock_irqsave(&hsotg->lock, flags);

/* Exit hibernation */
ret = dwc2_exit_hibernation(hsotg, true);
@@ -5249,8 +5245,7 @@ int dwc2_hcd_init(struct dwc2_hsotg *hsotg)
/* Don't support SG list at this point */
hcd->self.sg_tablesize = 0;

- if (!IS_ERR_OR_NULL(hsotg->uphy))
- otg_set_host(hsotg->uphy->otg, &hcd->self);
+ otg_set_host(hsotg->uphy->otg, &hcd->self);

/*
* Finish generic HCD initialization and start the HCD. This function
@@ -5306,8 +5301,7 @@ void dwc2_hcd_remove(struct dwc2_hsotg *hsotg)
return;
}

- if (!IS_ERR_OR_NULL(hsotg->uphy))
- otg_set_host(hsotg->uphy->otg, NULL);
+ otg_set_host(hsotg->uphy->otg, NULL);

usb_remove_hcd(hcd);
hsotg->priv = NULL;
diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c
index db9846396244..7e6fb116bcb2 100644
--- a/drivers/usb/dwc2/platform.c
+++ b/drivers/usb/dwc2/platform.c
@@ -130,11 +130,9 @@ static int __dwc2_lowlevel_hw_enable(struct dwc2_hsotg *hsotg)
if (ret)
return ret;

- if (hsotg->clk) {
- ret = clk_prepare_enable(hsotg->clk);
- if (ret)
- return ret;
- }
+ ret = clk_prepare_enable(hsotg->clk);
+ if (ret)
+ return ret;

if (hsotg->uphy) {
ret = usb_phy_init(hsotg->uphy);
@@ -182,8 +180,7 @@ static int __dwc2_lowlevel_hw_disable(struct dwc2_hsotg *hsotg)
if (ret)
return ret;

- if (hsotg->clk)
- clk_disable_unprepare(hsotg->clk);
+ clk_disable_unprepare(hsotg->clk);

ret = regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies),
hsotg->supplies);
--
2.11.0