usb: chipidea: ci_hdrc_imx: fix potential error pointer dereference in probe
authorDan Carpenter <dan.carpenter@oracle.com>
Wed, 17 Nov 2021 07:49:23 +0000 (10:49 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 17 Nov 2021 14:05:18 +0000 (15:05 +0100)
If the first call to devm_usb_get_phy_by_phandle(dev, "fsl,usbphy", 0)
fails with something other than -ENODEV then it leads to an error
pointer dereference.  For those errors we should just jump directly to
the error handling.

Fixes: 8253a34bfae3 ("usb: chipidea: ci_hdrc_imx: Also search for 'phys' phandle")
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Link: https://lore.kernel.org/r/20211117074923.GF5237@kili
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/chipidea/ci_hdrc_imx.c

index f1d1006..097142f 100644 (file)
@@ -420,15 +420,15 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
        data->phy = devm_usb_get_phy_by_phandle(dev, "fsl,usbphy", 0);
        if (IS_ERR(data->phy)) {
                ret = PTR_ERR(data->phy);
-               if (ret == -ENODEV) {
-                       data->phy = devm_usb_get_phy_by_phandle(dev, "phys", 0);
-                       if (IS_ERR(data->phy)) {
-                               ret = PTR_ERR(data->phy);
-                               if (ret == -ENODEV)
-                                       data->phy = NULL;
-                               else
-                                       goto err_clk;
-                       }
+               if (ret != -ENODEV)
+                       goto err_clk;
+               data->phy = devm_usb_get_phy_by_phandle(dev, "phys", 0);
+               if (IS_ERR(data->phy)) {
+                       ret = PTR_ERR(data->phy);
+                       if (ret == -ENODEV)
+                               data->phy = NULL;
+                       else
+                               goto err_clk;
                }
        }