ar71xx: Fix NULL pointer dereferece in at803x_link_change_notify()
authorAndrey Jr. Melnikov <temnota.am@gmail.com>
Sat, 7 Oct 2017 21:00:28 +0000 (00:00 +0300)
committerJohn Crispin <john@phrozen.org>
Sat, 7 Oct 2017 21:19:15 +0000 (23:19 +0200)
Check pdata pointer before use to avoid OOPS if dev_get_platdata() return
NULL.

Signed-off-by: Andrey Jr. Melnikov <temnota.am@gmail.com>
target/linux/ar71xx/patches-4.4/902-at803x-add-reset-gpio-pdata.patch

index 2244f882e7223625fc070f7a384bb81b2233bc83..efc8502bcd22217647a0aa49955d77642765c2ee 100644 (file)
@@ -42,7 +42,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
         */
        if (phydev->state == PHY_NOLINK) {
 -              if (priv->gpiod_reset && !priv->phy_reset) {
-+              if ((priv->gpiod_reset || pdata->has_reset_gpio) &&
++              if ((priv->gpiod_reset || (pdata && pdata->has_reset_gpio)) &&
 +                  !priv->phy_reset) {
                        struct at803x_context context;
  
@@ -52,7 +52,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
 -                      msleep(1);
 -                      gpiod_set_value(priv->gpiod_reset, 0);
 -                      msleep(1);
-+                      if (pdata->has_reset_gpio) {
++                      if (pdata && pdata->has_reset_gpio) {
 +                              gpio_set_value_cansleep(pdata->reset_gpio, 0);
 +                              msleep(1);
 +                              gpio_set_value_cansleep(pdata->reset_gpio, 1);