usb: dwc3: meson-g12a: fix USB2 PHY initialization on G12A and A1 SoCs
authorMartin Blumenstingl <martin.blumenstingl@googlemail.com>
Tue, 26 May 2020 20:29:43 +0000 (22:29 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 29 May 2020 10:21:26 +0000 (12:21 +0200)
commit347052e3bf1b62a25c11f7a673acfbaf554d67a1
tree45717fb5cddbd25da5a772418c58c275c3e7ffd3
parentbe8c1001a7e681e8813882a42ed51c8dbffd8800
usb: dwc3: meson-g12a: fix USB2 PHY initialization on G12A and A1 SoCs

dwc3_meson_g12a_usb2_init_phy() crashes with NULL pointer on an SM1
board (which uses the same USB setup as G12A) dereference as reported
by the Kernel CI bot. This is because of the following call flow:
  dwc3_meson_g12a_probe
    priv->drvdata->setup_regmaps
      dwc3_meson_g12a_setup_regmaps
        priv->usb2_ports is still 0 so priv->u2p_regmap[i] will be NULL
    dwc3_meson_g12a_get_phys
      initializes priv->usb2_ports
    priv->drvdata->usb_init
      dwc3_meson_g12a_usb_init
        dwc3_meson_g12a_usb_init_glue
          dwc3_meson_g12a_usb2_init
            priv->drvdata->usb2_init_phy
              dwc3_meson_g12a_usb2_init_phy
                dereferences priv->u2p_regmap[i]

Call priv->drvdata->setup_regmaps only after dwc3_meson_g12a_get_phys so
priv->usb2_ports is initialized and the regmaps will be set up
correctly. This fixes the NULL dereference later on.

Fixes: 013af227f58a97 ("usb: dwc3: meson-g12a: handle the phy and glue registers separately")
Reported-by: "kernelci.org bot" <bot@kernelci.org>
Acked-by: Felipe Balbi <balbi@kernel.org>
Acked-by: Neil Armstrong <narmstron@baylibre.com>
Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
Link: https://lore.kernel.org/r/20200526202943.715220-3-martin.blumenstingl@googlemail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/dwc3/dwc3-meson-g12a.c