Skip to content

Commit 9087637

Browse files
aasinclairrlubos
authored andcommitted
[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 <[email protected]> (cherry picked from commit c3a54ae)
1 parent 5d7a30b commit 9087637

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

drivers/regulator/regulator_common.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,13 @@ int regulator_enable(const struct device *dev)
107107
(void)k_mutex_lock(&data->lock, K_FOREVER);
108108
#endif
109109

110-
if (data->refcnt == 0) {
110+
data->refcnt++;
111+
112+
if (data->refcnt == 1) {
111113
ret = api->enable(dev);
112-
if (ret == 0) {
113-
data->refcnt++;
114+
if (ret < 0) {
115+
data->refcnt--;
116+
} else {
114117
regulator_delay(config->off_on_delay_us);
115118
}
116119
}

0 commit comments

Comments
 (0)