From 908763768e6de644d8d08a34dc3834c32563ab15 Mon Sep 17 00:00:00 2001 From: Andy Sinclair Date: Wed, 22 Nov 2023 16:34:02 +0000 Subject: [PATCH] [nrf fromtree] drivers: regulator: Fixed reference counting during enable Reference counting was broken when adding the enable delay. Now reverted to previous pattern. Signed-off-by: Andy Sinclair (cherry picked from commit c3a54ae1c34e939db83431bea354c0f4d0add0b3) --- drivers/regulator/regulator_common.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/regulator/regulator_common.c b/drivers/regulator/regulator_common.c index 7f33040d2d9..14866a3738f 100644 --- a/drivers/regulator/regulator_common.c +++ b/drivers/regulator/regulator_common.c @@ -107,10 +107,13 @@ int regulator_enable(const struct device *dev) (void)k_mutex_lock(&data->lock, K_FOREVER); #endif - if (data->refcnt == 0) { + data->refcnt++; + + if (data->refcnt == 1) { ret = api->enable(dev); - if (ret == 0) { - data->refcnt++; + if (ret < 0) { + data->refcnt--; + } else { regulator_delay(config->off_on_delay_us); } }