From e81f07eb19e573a4cdfbdb0d9588712c89a41e2c Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Mon, 3 Jan 2022 12:57:17 +0100 Subject: 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 Signed-off-by: Ahmad Fatoum Link: https://lore.barebox.org/20220103115718.1723730-5-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer --- drivers/regulator/core.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'drivers/regulator/core.c') 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; -- cgit v1.2.3