From cc29fc1182452a68becb9d507e3621ce073a48be Mon Sep 17 00:00:00 2001 From: Sylvio Alves Date: Mon, 17 Jun 2024 17:01:43 -0300 Subject: [PATCH] driver: eth_esp32: fix shared clock check Both MDIO and Ethernet drivers share the same clock subsystem. After clock control update in #73807, clock_control_on() now returns -EALREADY for already initialized clock subsystem. As a result, ethernet driver won't initialize as needed. Fixes #74440 Signed-off-by: Sylvio Alves --- drivers/ethernet/eth_esp32.c | 3 ++- drivers/mdio/mdio_esp32.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/ethernet/eth_esp32.c b/drivers/ethernet/eth_esp32.c index 689a6db7824..d7ae632bf9c 100644 --- a/drivers/ethernet/eth_esp32.c +++ b/drivers/ethernet/eth_esp32.c @@ -212,8 +212,9 @@ int eth_esp32_initialize(const struct device *dev) clock_control_subsys_t clock_subsys = (clock_control_subsys_t)DT_CLOCKS_CELL(DT_NODELABEL(eth), offset); + /* clock is shared, so do not bail out if already enabled */ res = clock_control_on(clock_dev, clock_subsys); - if (res != 0) { + if (res < 0 && res != -EALREADY) { goto err; } diff --git a/drivers/mdio/mdio_esp32.c b/drivers/mdio/mdio_esp32.c index 8e3e073bba0..b4c1a70f19a 100644 --- a/drivers/mdio/mdio_esp32.c +++ b/drivers/mdio/mdio_esp32.c @@ -104,8 +104,9 @@ static int mdio_esp32_initialize(const struct device *dev) clock_control_subsys_t clock_subsys = (clock_control_subsys_t)DT_CLOCKS_CELL(DT_NODELABEL(mdio), offset); + /* clock is shared, so do not bail out if already enabled */ res = clock_control_on(clock_dev, clock_subsys); - if (res != 0) { + if (res < 0 && res != -EALREADY) { goto err; }