UPSTREAM: regulator: core: Clear the supply pointer if enabling fails
authorJon Hunter <jonathanh@nvidia.com>
Thu, 21 Apr 2016 16:11:58 +0000 (17:11 +0100)
committerHuang, Tao <huangtao@rock-chips.com>
Mon, 6 Mar 2017 10:28:40 +0000 (18:28 +0800)
During the resolution of a regulator's supply, we may attempt to enable
the supply if the regulator itself is already enabled. If enabling the
supply fails, then we will call _regulator_put() for the supply.
However, the pointer to the supply has not been cleared for the
regulator and this will cause a crash if we then unregister the
regulator and attempt to call regulator_put() a second time for the
supply. Fix this by clearing the supply pointer if enabling the supply
after fails when resolving the supply for a regulator.

Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
(cherry picked from commit 8e5356a73604f53da6a1e0756727cb8f9f7bba17)

Change-Id: I3e83852db8c624fdd5b6c0bcab42c07289501a58
Signed-off-by: David Wu <david.wu@rock-chips.com>
drivers/regulator/core.c

index 4952530fc53b5eec1e42c085f19d459608d9d71a..d5cb2a8a1a0e8da03f9480c56aba09fb6bace9dc 100644 (file)
@@ -1595,6 +1595,7 @@ static int regulator_resolve_supply(struct regulator_dev *rdev)
                ret = regulator_enable(rdev->supply);
                if (ret < 0) {
                        _regulator_put(rdev->supply);
+                       rdev->supply = NULL;
                        return ret;
                }
        }