regulator: core: fix possible NULL dereference
authorSudip Mukherjee <sudipm.mukherjee@gmail.com>
Wed, 2 Sep 2015 10:44:06 +0000 (16:14 +0530)
committerMark Brown <broonie@kernel.org>
Wed, 2 Sep 2015 12:19:04 +0000 (13:19 +0100)
We were checking rdev->supply for NULL after dereferencing it. Lets
check for rdev->supply along with _regulator_is_enabled() and call
regulator_enable() only if rdev->supply is not NULL.

Signed-off-by: Sudip Mukherjee <sudip@vectorindia.org>
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/regulator/core.c

index de9f272a0faf75d7562665aebba60444338f21c5..7150ff6ef46b8df9091b62055e7649b3e8c605d0 100644 (file)
@@ -1422,11 +1422,10 @@ static int regulator_resolve_supply(struct regulator_dev *rdev)
                return ret;
 
        /* Cascade always-on state to supply */
-       if (_regulator_is_enabled(rdev)) {
+       if (_regulator_is_enabled(rdev) && rdev->supply) {
                ret = regulator_enable(rdev->supply);
                if (ret < 0) {
-                       if (rdev->supply)
-                               _regulator_put(rdev->supply);
+                       _regulator_put(rdev->supply);
                        return ret;
                }
        }