Skip to content

Commit 0c717d0

Browse files
vireshkrafaeljw
authored andcommitted
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: 7d34d56 (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>
1 parent c88c395 commit 0c717d0

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

drivers/base/power/opp/core.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev)
257257
}
258258

259259
reg = dev_opp->regulator;
260-
if (IS_ERR_OR_NULL(reg)) {
260+
if (IS_ERR(reg)) {
261261
/* Regulator may not be required for device */
262262
if (reg)
263263
dev_err(dev, "%s: Invalid regulator (%ld)\n", __func__,
@@ -798,6 +798,9 @@ static struct device_opp *_add_device_opp(struct device *dev)
798798
of_node_put(np);
799799
}
800800

801+
/* Set regulator to a non-NULL error value */
802+
dev_opp->regulator = ERR_PTR(-ENXIO);
803+
801804
/* Find clk for the device */
802805
dev_opp->clk = clk_get(dev, NULL);
803806
if (IS_ERR(dev_opp->clk)) {
@@ -845,7 +848,7 @@ static void _remove_device_opp(struct device_opp *dev_opp)
845848
if (dev_opp->prop_name)
846849
return;
847850

848-
if (!IS_ERR_OR_NULL(dev_opp->regulator))
851+
if (!IS_ERR(dev_opp->regulator))
849852
return;
850853

851854
/* Release clk */
@@ -975,7 +978,7 @@ static bool _opp_supported_by_regulators(struct dev_pm_opp *opp,
975978
{
976979
struct regulator *reg = dev_opp->regulator;
977980

978-
if (!IS_ERR_OR_NULL(reg) &&
981+
if (!IS_ERR(reg) &&
979982
!regulator_is_supported_voltage(reg, opp->u_volt_min,
980983
opp->u_volt_max)) {
981984
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)
14411444
}
14421445

14431446
/* 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))) {
14451448
ret = -EBUSY;
14461449
goto err;
14471450
}
@@ -1492,7 +1495,7 @@ void dev_pm_opp_put_regulator(struct device *dev)
14921495
goto unlock;
14931496
}
14941497

1495-
if (IS_ERR_OR_NULL(dev_opp->regulator)) {
1498+
if (IS_ERR(dev_opp->regulator)) {
14961499
dev_err(dev, "%s: Doesn't have regulator set\n", __func__);
14971500
goto unlock;
14981501
}
@@ -1501,7 +1504,7 @@ void dev_pm_opp_put_regulator(struct device *dev)
15011504
WARN_ON(!list_empty(&dev_opp->opp_list));
15021505

15031506
regulator_put(dev_opp->regulator);
1504-
dev_opp->regulator = ERR_PTR(-EINVAL);
1507+
dev_opp->regulator = ERR_PTR(-ENXIO);
15051508

15061509
/* Try freeing device_opp if this was the last blocking resource */
15071510
_remove_device_opp(dev_opp);

0 commit comments

Comments
 (0)