[PATCH 1/9] regulator/core: _regulator_get: simplify error returns

From: Michał Mirosław
Date: Wed Aug 30 2023 - 18:43:32 EST


Remove unnecessary stores to `regulator`.

Signed-off-by: Michał Mirosław <mirq-linux@xxxxxxxxxxxx>
---
drivers/regulator/core.c | 18 ++++++------------
1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 662711063433..d440cd137c38 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -2209,15 +2209,13 @@ struct regulator *_regulator_get(struct device *dev, const char *id,
}

if (rdev->exclusive) {
- regulator = ERR_PTR(-EPERM);
put_device(&rdev->dev);
- return regulator;
+ return ERR_PTR(-EPERM);
}

if (get_type == EXCLUSIVE_GET && rdev->open_count) {
- regulator = ERR_PTR(-EBUSY);
put_device(&rdev->dev);
- return regulator;
+ return ERR_PTR(-EBUSY);
}

mutex_lock(&regulator_list_mutex);
@@ -2225,32 +2223,28 @@ struct regulator *_regulator_get(struct device *dev, const char *id,
mutex_unlock(&regulator_list_mutex);

if (ret != 0) {
- regulator = ERR_PTR(-EPROBE_DEFER);
put_device(&rdev->dev);
- return regulator;
+ return ERR_PTR(-EPROBE_DEFER);
}

ret = regulator_resolve_supply(rdev);
if (ret < 0) {
- regulator = ERR_PTR(ret);
put_device(&rdev->dev);
- return regulator;
+ return ERR_PTR(ret);
}

if (!try_module_get(rdev->owner)) {
- regulator = ERR_PTR(-EPROBE_DEFER);
put_device(&rdev->dev);
- return regulator;
+ return ERR_PTR(-EPROBE_DEFER);
}

regulator_lock(rdev);
regulator = create_regulator(rdev, dev, id);
regulator_unlock(rdev);
if (regulator == NULL) {
- regulator = ERR_PTR(-ENOMEM);
module_put(rdev->owner);
put_device(&rdev->dev);
- return regulator;
+ return ERR_PTR(-ENOMEM);
}

rdev->open_count++;
--
2.39.2