Skip to content

Commit 2a1de56

Browse files
wensbroonie
authored andcommitted
regulator: Split up _regulator_get()
_regulator_get() contains a lot of common code doing checks prior to the regulator lookup and housekeeping work after the lookup. Almost all the code could be shared with a OF-specific variant of _regulator_get(). Split out the common parts so that they can be reused. The OF-specific version of _regulator_get() will be added in a subsequent patch. No functional changes were made. Signed-off-by: Chen-Yu Tsai <wenst@chromium.org> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Link: https://patch.msgid.link/20240911072751.365361-4-wenst@chromium.org Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent fb9ce84 commit 2a1de56

2 files changed

Lines changed: 47 additions & 11 deletions

File tree

drivers/regulator/core.c

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2106,26 +2106,43 @@ static int regulator_resolve_supply(struct regulator_dev *rdev)
21062106
return ret;
21072107
}
21082108

2109-
/* Internal regulator request function */
2110-
struct regulator *_regulator_get(struct device *dev, const char *id,
2111-
enum regulator_get_type get_type)
2109+
/* common pre-checks for regulator requests */
2110+
int _regulator_get_common_check(struct device *dev, const char *id,
2111+
enum regulator_get_type get_type)
21122112
{
2113-
struct regulator_dev *rdev;
2114-
struct regulator *regulator;
2115-
struct device_link *link;
2116-
int ret;
2117-
21182113
if (get_type >= MAX_GET_TYPE) {
21192114
dev_err(dev, "invalid type %d in %s\n", get_type, __func__);
2120-
return ERR_PTR(-EINVAL);
2115+
return -EINVAL;
21212116
}
21222117

21232118
if (id == NULL) {
21242119
dev_err(dev, "regulator request with no identifier\n");
2125-
return ERR_PTR(-EINVAL);
2120+
return -EINVAL;
21262121
}
21272122

2128-
rdev = regulator_dev_lookup(dev, id);
2123+
return 0;
2124+
}
2125+
2126+
/**
2127+
* _regulator_get_common - Common code for regulator requests
2128+
* @rdev: regulator device pointer as returned by *regulator_dev_lookup()
2129+
* Its reference count is expected to have been incremented.
2130+
* @dev: device used for dev_printk messages
2131+
* @id: Supply name or regulator ID
2132+
* @get_type: enum regulator_get_type value corresponding to type of request
2133+
*
2134+
* Returns: pointer to struct regulator corresponding to @rdev, or ERR_PTR()
2135+
* encoded error.
2136+
*
2137+
* This function should be chained with *regulator_dev_lookup() functions.
2138+
*/
2139+
struct regulator *_regulator_get_common(struct regulator_dev *rdev, struct device *dev,
2140+
const char *id, enum regulator_get_type get_type)
2141+
{
2142+
struct regulator *regulator;
2143+
struct device_link *link;
2144+
int ret;
2145+
21292146
if (IS_ERR(rdev)) {
21302147
ret = PTR_ERR(rdev);
21312148

@@ -2241,6 +2258,21 @@ struct regulator *_regulator_get(struct device *dev, const char *id,
22412258
return regulator;
22422259
}
22432260

2261+
/* Internal regulator request function */
2262+
struct regulator *_regulator_get(struct device *dev, const char *id,
2263+
enum regulator_get_type get_type)
2264+
{
2265+
struct regulator_dev *rdev;
2266+
int ret;
2267+
2268+
ret = _regulator_get_common_check(dev, id, get_type);
2269+
if (ret)
2270+
return ERR_PTR(ret);
2271+
2272+
rdev = regulator_dev_lookup(dev, id);
2273+
return _regulator_get_common(rdev, dev, id, get_type);
2274+
}
2275+
22442276
/**
22452277
* regulator_get - lookup and obtain a reference to a regulator.
22462278
* @dev: device for regulator "consumer"

drivers/regulator/internal.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ enum regulator_get_type {
121121
MAX_GET_TYPE
122122
};
123123

124+
int _regulator_get_common_check(struct device *dev, const char *id,
125+
enum regulator_get_type get_type);
126+
struct regulator *_regulator_get_common(struct regulator_dev *rdev, struct device *dev,
127+
const char *id, enum regulator_get_type get_type);
124128
struct regulator *_regulator_get(struct device *dev, const char *id,
125129
enum regulator_get_type get_type);
126130
int _regulator_bulk_get(struct device *dev, int num_consumers,

0 commit comments

Comments
 (0)