[PATCH] regulator: core: don't disable regulator if is_enabled return error.

From: Pi-Hsun Shih
Date: Fri Nov 06 2020 - 01:49:32 EST


In regulator_late_cleanup when is_enabled failed, don't try to disable
the regulator since it would likely to fail too and causing confusing
error messages.

Signed-off-by: Pi-Hsun Shih <pihsun@xxxxxxxxxxxx>
---

This is encountered while using drivers/regulator/cros-ec-regulator.c.
Since the driver controls the regulator through ChromeOS EC host
commands, it is not available when doing suspend / resume.

But since the regulator_late_cleanup is delayed to 30 seconds after
boot, it is possible that the regulator_late_cleanup is run during
suspend / resume, which cause the is_enabled call to fail, and printing
out some confusing error messages later when trying to disable the
regulator and fail.

This commit attempts to address part of this issue by not trying to
disable the regulator if the is_enabled call failed.

---
drivers/regulator/core.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index a5ad553da8cd..70168f2a53ed 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -5843,13 +5843,14 @@ static int regulator_late_cleanup(struct device *dev, void *data)
if (rdev->use_count)
goto unlock;

- /* If we can't read the status assume it's on. */
+ /* If we can't read the status assume it's always on. */
if (ops->is_enabled)
enabled = ops->is_enabled(rdev);
else
enabled = 1;

- if (!enabled)
+ /* But if reading the status failed, assume that it's off. */
+ if (enabled <= 0)
goto unlock;

if (have_full_constraints()) {

base-commit: 521b619acdc8f1f5acdac15b84f81fd9515b2aff
--
2.29.1.341.ge80a0c044ae-goog