From d687e15133f66f00e9b36fd0abe2ba700e89ff95 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 689a6db7824dbda..d7ae632bf9c5608 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 8e3e073bba0872a..b4c1a70f19af816 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; }