diff --git a/drivers/ethernet/phy/phy_microchip_ksz8081.c b/drivers/ethernet/phy/phy_microchip_ksz8081.c index 61a97ca03e7cdb..18279673e4bf18 100644 --- a/drivers/ethernet/phy/phy_microchip_ksz8081.c +++ b/drivers/ethernet/phy/phy_microchip_ksz8081.c @@ -161,13 +161,11 @@ static int phy_mc_ksz8081_get_link(const struct device *dev, ret = phy_mc_ksz8081_read(dev, MII_BMSR, &bmsr); if (ret) { LOG_ERR("Error reading phy (%d) basic status register", config->addr); - k_mutex_unlock(&data->mutex); - return ret; + goto done; } state->is_up = bmsr & MII_BMSR_LINK_STATUS; if (!state->is_up) { - k_mutex_unlock(&data->mutex); goto result; } @@ -175,21 +173,16 @@ static int phy_mc_ksz8081_get_link(const struct device *dev, ret = phy_mc_ksz8081_read(dev, MII_ANAR, &anar); if (ret) { LOG_ERR("Error reading phy (%d) advertising register", config->addr); - k_mutex_unlock(&data->mutex); - return ret; + goto done; } /* Read link partner capability */ ret = phy_mc_ksz8081_read(dev, MII_ANLPAR, &anlpar); if (ret) { LOG_ERR("Error reading phy (%d) link partner register", config->addr); - k_mutex_unlock(&data->mutex); - return ret; + goto done; } - /* Unlock mutex */ - k_mutex_unlock(&data->mutex); - uint32_t mutual_capabilities = anar & anlpar; if (mutual_capabilities & MII_ADVERTISE_100_FULL) { @@ -214,6 +207,9 @@ static int phy_mc_ksz8081_get_link(const struct device *dev, } } +done: + k_mutex_unlock(&data->mutex); + return ret; } @@ -269,9 +265,6 @@ static int phy_mc_ksz8081_static_cfg(const struct device *dev) static int phy_mc_ksz8081_reset(const struct device *dev) { -#if DT_ANY_INST_HAS_PROP_STATUS_OKAY(reset_gpios) - const struct mc_ksz8081_config *config = dev->config; -#endif /* DT_ANY_INST_HAS_PROP_STATUS_OKAY(reset_gpios) */ struct mc_ksz8081_data *data = dev->data; int ret; @@ -283,27 +276,27 @@ static int phy_mc_ksz8081_reset(const struct device *dev) } #if DT_ANY_INST_HAS_PROP_STATUS_OKAY(reset_gpios) - if (!config->reset_gpio.port) { - goto skip_reset_gpio; - } + const struct mc_ksz8081_config *config = dev->config; - /* Start reset */ - ret = gpio_pin_set_dt(&config->reset_gpio, 0); - if (ret) { - goto done; - } + if (config->reset_gpio.port) { + /* Start reset */ + ret = gpio_pin_set_dt(&config->reset_gpio, 0); + if (ret) { + goto done; + } - /* Wait for at least 500 us as specified by datasheet */ - k_busy_wait(1000); + /* Wait for at least 500 us as specified by datasheet */ + k_busy_wait(1000); - /* Reset over */ - ret = gpio_pin_set_dt(&config->reset_gpio, 1); + /* Reset over */ + ret = gpio_pin_set_dt(&config->reset_gpio, 1); - /* After deasserting reset, must wait at least 100 us to use programming interface */ - k_busy_wait(200); + /* After deasserting reset, must wait at least 100 us to use programming interface + */ + k_busy_wait(200); - goto done; -skip_reset_gpio: + goto done; + } #endif /* DT_ANY_INST_HAS_PROP_STATUS_OKAY(reset_gpios) */ ret = phy_mc_ksz8081_write(dev, MII_BMCR, MII_BMCR_RESET); if (ret) {