Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Chen-Yu Tsai and committed by
Mark Brown
2a1de567 fb9ce84a

+47 -11
+43 -11
drivers/regulator/core.c
··· 2106 2106 return ret; 2107 2107 } 2108 2108 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) 2112 2112 { 2113 - struct regulator_dev *rdev; 2114 - struct regulator *regulator; 2115 - struct device_link *link; 2116 - int ret; 2117 - 2118 2113 if (get_type >= MAX_GET_TYPE) { 2119 2114 dev_err(dev, "invalid type %d in %s\n", get_type, __func__); 2120 - return ERR_PTR(-EINVAL); 2115 + return -EINVAL; 2121 2116 } 2122 2117 2123 2118 if (id == NULL) { 2124 2119 dev_err(dev, "regulator request with no identifier\n"); 2125 - return ERR_PTR(-EINVAL); 2120 + return -EINVAL; 2126 2121 } 2127 2122 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 + 2129 2146 if (IS_ERR(rdev)) { 2130 2147 ret = PTR_ERR(rdev); 2131 2148 ··· 2256 2239 regulator->device_link = true; 2257 2240 2258 2241 return regulator; 2242 + } 2243 + 2244 + /* Internal regulator request function */ 2245 + struct regulator *_regulator_get(struct device *dev, const char *id, 2246 + enum regulator_get_type get_type) 2247 + { 2248 + struct regulator_dev *rdev; 2249 + int ret; 2250 + 2251 + ret = _regulator_get_common_check(dev, id, get_type); 2252 + if (ret) 2253 + return ERR_PTR(ret); 2254 + 2255 + rdev = regulator_dev_lookup(dev, id); 2256 + return _regulator_get_common(rdev, dev, id, get_type); 2259 2257 } 2260 2258 2261 2259 /**
+4
drivers/regulator/internal.h
··· 121 121 MAX_GET_TYPE 122 122 }; 123 123 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); 124 128 struct regulator *_regulator_get(struct device *dev, const char *id, 125 129 enum regulator_get_type get_type); 126 130 int _regulator_bulk_get(struct device *dev, int num_consumers,