usb: dwc3: Validate the maximum_speed parameter
Check that dwc->maximum_speed is set to a valid value. Also add an error when we use it later if we encounter an invalid value. Signed-off-by: John Youn <johnyoun@synopsys.com> Signed-off-by: Felipe Balbi <balbi@kernel.org>
This commit is contained in:
parent
5266a7603f
commit
77966eb85e
|
@ -1012,8 +1012,20 @@ static int dwc3_probe(struct platform_device *pdev)
|
||||||
goto err1;
|
goto err1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* default to superspeed if no maximum_speed passed */
|
/* Check the maximum_speed parameter */
|
||||||
if (dwc->maximum_speed == USB_SPEED_UNKNOWN) {
|
switch (dwc->maximum_speed) {
|
||||||
|
case USB_SPEED_LOW:
|
||||||
|
case USB_SPEED_FULL:
|
||||||
|
case USB_SPEED_HIGH:
|
||||||
|
case USB_SPEED_SUPER:
|
||||||
|
case USB_SPEED_SUPER_PLUS:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
dev_err(dev, "invalid maximum_speed parameter %d\n",
|
||||||
|
dwc->maximum_speed);
|
||||||
|
/* fall through */
|
||||||
|
case USB_SPEED_UNKNOWN:
|
||||||
|
/* default to superspeed */
|
||||||
dwc->maximum_speed = USB_SPEED_SUPER;
|
dwc->maximum_speed = USB_SPEED_SUPER;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1023,6 +1035,8 @@ static int dwc3_probe(struct platform_device *pdev)
|
||||||
(DWC3_GHWPARAMS3_SSPHY_IFC(dwc->hwparams.hwparams3) ==
|
(DWC3_GHWPARAMS3_SSPHY_IFC(dwc->hwparams.hwparams3) ==
|
||||||
DWC3_GHWPARAMS3_SSPHY_IFC_GEN2))
|
DWC3_GHWPARAMS3_SSPHY_IFC_GEN2))
|
||||||
dwc->maximum_speed = USB_SPEED_SUPER_PLUS;
|
dwc->maximum_speed = USB_SPEED_SUPER_PLUS;
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Adjust Frame Length */
|
/* Adjust Frame Length */
|
||||||
|
|
|
@ -1670,10 +1670,13 @@ static int dwc3_gadget_start(struct usb_gadget *g,
|
||||||
case USB_SPEED_SUPER_PLUS:
|
case USB_SPEED_SUPER_PLUS:
|
||||||
reg |= DWC3_DSTS_SUPERSPEED_PLUS;
|
reg |= DWC3_DSTS_SUPERSPEED_PLUS;
|
||||||
break;
|
break;
|
||||||
case USB_SPEED_SUPER: /* FALLTHROUGH */
|
|
||||||
case USB_SPEED_UNKNOWN: /* FALTHROUGH */
|
|
||||||
default:
|
default:
|
||||||
reg |= DWC3_DSTS_SUPERSPEED;
|
dev_err(dwc->dev, "invalid dwc->maximum_speed (%d)\n",
|
||||||
|
dwc->maximum_speed);
|
||||||
|
/* fall through */
|
||||||
|
case USB_SPEED_SUPER:
|
||||||
|
reg |= DWC3_DCFG_SUPERSPEED;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dwc3_writel(dwc->regs, DWC3_DCFG, reg);
|
dwc3_writel(dwc->regs, DWC3_DCFG, reg);
|
||||||
|
|
Loading…
Reference in New Issue