aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorViresh Kumar <viresh.kumar@linaro.org>2016-02-15 11:26:42 -0500
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2016-02-16 07:12:41 -0500
commit0c717d0f9cb46259dce5272705adce64a2d646d9 (patch)
treee2b8424dd7931c98f730720e7062251bdf6b84fd
parentc88c395f4a6485f23f81e385c79945d68bcd5c5d (diff)
PM / OPP: Initialize regulator pointer to an error value
We are currently required to do two checks for regulator pointer: IS_ERR() and IS_NULL(). And multiple instances are reported, about both of these not being used consistently and so resulting in crashes. Fix that by initializing regulator pointer with an error value and checking it only against an error. This makes code more consistent and more efficient. Fixes: 7d34d56ef334 (PM / OPP: Disable OPPs that aren't supported by the regulator) Reported-and-tested-by: Jon Hunter <jonathanh@nvidia.com> Reported-and-tested-by: Tony Lindgren <tony@atomide.com> Reported-and-tested-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> [ rjw: Initialize to -ENXIO ] Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
-rw-r--r--drivers/base/power/opp/core.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/drivers/base/power/opp/core.c b/drivers/base/power/opp/core.c
index 19fd7e7a3969..5fb2f061129e 100644
--- a/drivers/base/power/opp/core.c
+++ b/drivers/base/power/opp/core.c
@@ -257,7 +257,7 @@ unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev)
257 } 257 }
258 258
259 reg = dev_opp->regulator; 259 reg = dev_opp->regulator;
260 if (IS_ERR_OR_NULL(reg)) { 260 if (IS_ERR(reg)) {
261 /* Regulator may not be required for device */ 261 /* Regulator may not be required for device */
262 if (reg) 262 if (reg)
263 dev_err(dev, "%s: Invalid regulator (%ld)\n", __func__, 263 dev_err(dev, "%s: Invalid regulator (%ld)\n", __func__,
@@ -798,6 +798,9 @@ static struct device_opp *_add_device_opp(struct device *dev)
798 of_node_put(np); 798 of_node_put(np);
799 } 799 }
800 800
801 /* Set regulator to a non-NULL error value */
802 dev_opp->regulator = ERR_PTR(-ENXIO);
803
801 /* Find clk for the device */ 804 /* Find clk for the device */
802 dev_opp->clk = clk_get(dev, NULL); 805 dev_opp->clk = clk_get(dev, NULL);
803 if (IS_ERR(dev_opp->clk)) { 806 if (IS_ERR(dev_opp->clk)) {
@@ -845,7 +848,7 @@ static void _remove_device_opp(struct device_opp *dev_opp)
845 if (dev_opp->prop_name) 848 if (dev_opp->prop_name)
846 return; 849 return;
847 850
848 if (!IS_ERR_OR_NULL(dev_opp->regulator)) 851 if (!IS_ERR(dev_opp->regulator))
849 return; 852 return;
850 853
851 /* Release clk */ 854 /* Release clk */
@@ -975,7 +978,7 @@ static bool _opp_supported_by_regulators(struct dev_pm_opp *opp,
975{ 978{
976 struct regulator *reg = dev_opp->regulator; 979 struct regulator *reg = dev_opp->regulator;
977 980
978 if (!IS_ERR_OR_NULL(reg) && 981 if (!IS_ERR(reg) &&
979 !regulator_is_supported_voltage(reg, opp->u_volt_min, 982 !regulator_is_supported_voltage(reg, opp->u_volt_min,
980 opp->u_volt_max)) { 983 opp->u_volt_max)) {
981 pr_warn("%s: OPP minuV: %lu maxuV: %lu, not supported by regulator\n", 984 pr_warn("%s: OPP minuV: %lu maxuV: %lu, not supported by regulator\n",
@@ -1441,7 +1444,7 @@ int dev_pm_opp_set_regulator(struct device *dev, const char *name)
1441 } 1444 }
1442 1445
1443 /* Already have a regulator set */ 1446 /* Already have a regulator set */
1444 if (WARN_ON(!IS_ERR_OR_NULL(dev_opp->regulator))) { 1447 if (WARN_ON(!IS_ERR(dev_opp->regulator))) {
1445 ret = -EBUSY; 1448 ret = -EBUSY;
1446 goto err; 1449 goto err;
1447 } 1450 }
@@ -1492,7 +1495,7 @@ void dev_pm_opp_put_regulator(struct device *dev)
1492 goto unlock; 1495 goto unlock;
1493 } 1496 }
1494 1497
1495 if (IS_ERR_OR_NULL(dev_opp->regulator)) { 1498 if (IS_ERR(dev_opp->regulator)) {
1496 dev_err(dev, "%s: Doesn't have regulator set\n", __func__); 1499 dev_err(dev, "%s: Doesn't have regulator set\n", __func__);
1497 goto unlock; 1500 goto unlock;
1498 } 1501 }
@@ -1501,7 +1504,7 @@ void dev_pm_opp_put_regulator(struct device *dev)
1501 WARN_ON(!list_empty(&dev_opp->opp_list)); 1504 WARN_ON(!list_empty(&dev_opp->opp_list));
1502 1505
1503 regulator_put(dev_opp->regulator); 1506 regulator_put(dev_opp->regulator);
1504 dev_opp->regulator = ERR_PTR(-EINVAL); 1507 dev_opp->regulator = ERR_PTR(-ENXIO);
1505 1508
1506 /* Try freeing device_opp if this was the last blocking resource */ 1509 /* Try freeing device_opp if this was the last blocking resource */
1507 _remove_device_opp(dev_opp); 1510 _remove_device_opp(dev_opp);