Skip to content

Commit

Permalink
drivers: regulator: fix reference count underflow
Browse files Browse the repository at this point in the history
Fixes regulator reference count underflow and adds error code
for attempting to disable an already disabled regulator

(cherry picked from commit 95622e4)

Original-Signed-off-by: Vladislav Litvinov <vladislav.litvinov@nordicsemi.no>
GitOrigin-RevId: 95622e4
Cr-Build-Id: 8740696253239544497
Cr-Build-Url: https://cr-buildbucket.appspot.com/build/8740696253239544497
Change-Id: I290a61f998561472f103a8c6152a848a50ab539f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/zephyr/+/5760302
Tested-by: ChromeOS Prod (Robot) <chromeos-ci-prod@chromeos-bot.iam.gserviceaccount.com>
Tested-by: Fabio Baltieri <fabiobaltieri@google.com>
Reviewed-by: Fabio Baltieri <fabiobaltieri@google.com>
Commit-Queue: Fabio Baltieri <fabiobaltieri@google.com>
  • Loading branch information
WalkingTalkingPotato authored and Chromeos LUCI committed Aug 2, 2024
1 parent 01c3f99 commit 2095bb5
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions drivers/regulator/regulator_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,14 @@ int regulator_disable(const struct device *dev)
(void)k_mutex_lock(&data->lock, K_FOREVER);
#endif

data->refcnt--;
if (data->refcnt > 0) {
data->refcnt--;

if (data->refcnt == 0) {
ret = api->disable(dev);
if (ret < 0) {
data->refcnt++;
if (data->refcnt == 0) {
ret = api->disable(dev);
if (ret < 0) {
data->refcnt++;
}
}
}

Expand Down

0 comments on commit 2095bb5

Please sign in to comment.