diff options
author | Ahmad Fatoum <a.fatoum@pengutronix.de> | 2022-01-03 12:57:17 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2022-01-05 08:28:37 +0100 |
commit | e81f07eb19e573a4cdfbdb0d9588712c89a41e2c (patch) | |
tree | b940a6bcc5b307c4148b45077c17cdb8d4d77cd5 /drivers | |
parent | ae829c0f35e6c3cf5e3d0dac38e63b6376204ac2 (diff) | |
download | barebox-e81f07eb19e573a4cdfbdb0d9588712c89a41e2c.tar.gz barebox-e81f07eb19e573a4cdfbdb0d9588712c89a41e2c.tar.xz |
regulator: fix broken reference counting on disable
Reference count is maintained correctly when enabling, but the very
first disable will ignore the reference count and disable the regulator
unconditionally. Make disable with an enable_count > 1 a no-op to fix
this.
Reported-by: Enrico Jorns <ejo@pengutronix.de>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Link: https://lore.barebox.org/20220103115718.1723730-5-a.fatoum@pengutronix.de
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/regulator/core.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index d1d3a36dfc..ac4141c1cd 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -71,6 +71,11 @@ static int regulator_disable_internal(struct regulator_internal *ri) if (!ri->enable_count) return -EINVAL; + if (ri->enable_count > 1) { + ri->enable_count--; + return 0; + } + if (!ri->rdev->desc->ops->disable) return -ENOSYS; |