提交 a4d7641f 编写于 作者: D Dmitry Torokhov 提交者: Mark Brown

regulator: core: simplify _regulator_get()

The code in _regulator_get() got a bit confusing over time, with control
flow jumping to a label from couple of places. Let's untangle it a bit by
doing the following:

1. Make handling of missing supplies and substituting them with dummy
regulators more explicit:

- check if we not have full constraints and refuse considering dummy
  regulators with appropriate message;

- use "switch (get_type)" to handle different types of request explicitly
  as well. "Normal" requests will get dummies, exclusive will not and
  will notify user about that; optional will fail silently.

2. Stop jumping to a label in the middle of the function but instead have
proper conditional flow. I believe jumps should be reserved for error
handling, breaking from inner loop, or restarting a loop, but not for
implementing normal conditional flow.
Signed-off-by: NDmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: NMark Brown <broonie@kernel.org>
上级 163478da
...@@ -1588,7 +1588,7 @@ struct regulator *_regulator_get(struct device *dev, const char *id, ...@@ -1588,7 +1588,7 @@ struct regulator *_regulator_get(struct device *dev, const char *id,
{ {
struct regulator_dev *rdev; struct regulator_dev *rdev;
struct regulator *regulator; struct regulator *regulator;
const char *devname = NULL; const char *devname = dev ? dev_name(dev) : "deviceless";
int ret; int ret;
if (get_type >= MAX_GET_TYPE) { if (get_type >= MAX_GET_TYPE) {
...@@ -1601,45 +1601,47 @@ struct regulator *_regulator_get(struct device *dev, const char *id, ...@@ -1601,45 +1601,47 @@ struct regulator *_regulator_get(struct device *dev, const char *id,
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
} }
if (dev)
devname = dev_name(dev);
rdev = regulator_dev_lookup(dev, id); rdev = regulator_dev_lookup(dev, id);
if (!IS_ERR(rdev)) if (IS_ERR(rdev)) {
goto found;
ret = PTR_ERR(rdev); ret = PTR_ERR(rdev);
regulator = ERR_PTR(ret);
/* /*
* If we have return value from dev_lookup fail, we do not expect to * If regulator_dev_lookup() fails with error other
* succeed, so, quit with appropriate error value * than -ENODEV our job here is done, we simply return it.
*/ */
if (ret && ret != -ENODEV) if (ret != -ENODEV)
return regulator; return ERR_PTR(ret);
if (!devname) if (!have_full_constraints()) {
devname = "deviceless"; dev_warn(dev,
"incomplete constraints, dummy supplies not allowed\n");
return ERR_PTR(-ENODEV);
}
switch (get_type) {
case NORMAL_GET:
/* /*
* Assume that a regulator is physically present and enabled * Assume that a regulator is physically present and
* even if it isn't hooked up and just provide a dummy. * enabled, even if it isn't hooked up, and just
* provide a dummy.
*/ */
if (have_full_constraints() && get_type == NORMAL_GET) { dev_warn(dev,
pr_warn("%s supply %s not found, using dummy regulator\n", "%s supply %s not found, using dummy regulator\n",
devname, id); devname, id);
rdev = dummy_regulator_rdev; rdev = dummy_regulator_rdev;
get_device(&rdev->dev); get_device(&rdev->dev);
goto found; break;
/* Don't log an error when called from regulator_get_optional() */
} else if (!have_full_constraints() || get_type == EXCLUSIVE_GET) {
dev_warn(dev, "dummy supplies not allowed\n");
}
return regulator; case EXCLUSIVE_GET:
dev_warn(dev,
"dummy supplies not allowed for exclusive requests\n");
/* fall through */
default:
return ERR_PTR(-ENODEV);
}
}
found:
if (rdev->exclusive) { if (rdev->exclusive) {
regulator = ERR_PTR(-EPERM); regulator = ERR_PTR(-EPERM);
put_device(&rdev->dev); put_device(&rdev->dev);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册