usb: dwc3: rockchip: fix xhci NULL pointer dereference
authorWu Liang feng <wulf@rock-chips.com>
Thu, 13 Oct 2016 06:08:52 +0000 (14:08 +0800)
committerHuang, Tao <huangtao@rock-chips.com>
Thu, 13 Oct 2016 06:50:29 +0000 (14:50 +0800)
If DWC3 works as peripheral only mode, XHCI HCD will
not be created and added, so we should only get XHCI
HCD in host mode.

Change-Id: Iefb02431d6a973050986963bbabe0a943283f4b3
Signed-off-by: Wu Liang feng <wulf@rock-chips.com>
drivers/usb/dwc3/dwc3-rockchip.c

index 8a03034675025242f6e1bc886cbf9498ecd5f588..198f67158c3360e9efe382e83aade41c106eacd6 100644 (file)
@@ -81,7 +81,7 @@ static void dwc3_rockchip_otg_extcon_evt_work(struct work_struct *work)
                container_of(work, struct dwc3_rockchip, otg_work);
        struct dwc3             *dwc = rockchip->dwc;
        struct extcon_dev       *edev = rockchip->edev;
-       struct usb_hcd          *hcd = dev_get_drvdata(&dwc->xhci->dev);
+       struct usb_hcd          *hcd;
        unsigned long           flags;
        int                     ret;
        u32                     reg;
@@ -180,6 +180,8 @@ static void dwc3_rockchip_otg_extcon_evt_work(struct work_struct *work)
                 */
                usleep_range(10000, 11000);
 
+               hcd = dev_get_drvdata(&dwc->xhci->dev);
+
                if (hcd->state == HC_STATE_HALT) {
                        usb_add_hcd(hcd, hcd->irq, IRQF_SHARED);
                        usb_add_hcd(hcd->shared_hcd, hcd->irq, IRQF_SHARED);