usb: dwc3: qcom: Improve error handling
authorLee Jones <lee.jones@linaro.org>
Mon, 17 Jun 2019 12:51:05 +0000 (13:51 +0100)
committerFelipe Balbi <felipe.balbi@linux.intel.com>
Tue, 18 Jun 2019 08:58:29 +0000 (11:58 +0300)
dwc3_qcom_clk_init() is called with of_count_phandle_with_args() as an
argument.  If of_count_phandle_with_args() returns an error, the number
of clocks will be a negative value and will lead to undefined behaviour.

Ensure we check for an error before attempting to blindly use the value.

Signed-off-by: Lee Jones <lee.jones@linaro.org>
Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
drivers/usb/dwc3/dwc3-qcom.c

index 2d050303d564727c14ce0532319a218c9db169e9..c59e9d8e8609aa87f2791df17748fd801efb2892 100644 (file)
@@ -409,6 +409,9 @@ static int dwc3_qcom_clk_init(struct dwc3_qcom *qcom, int count)
        if (!np || !count)
                return 0;
 
+       if (count < 0)
+               return count;
+
        qcom->num_clocks = count;
 
        qcom->clks = devm_kcalloc(dev, qcom->num_clocks,