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

regulator: gpio-regulator: do not open-code counting and access of dt array elements

Open coding the counting of elements in a dt-property is abstracted by the newly
introduced of_property_count_uXX_elems functions. Additionally the raw iteration
over the states element exposes the endian conversion and dtb-format details,
which according to Mark Rutland "would be nice to limit [...] to of_ helper
functions".

Thus change gpio-regulator to use the helper for element counting and
of_property_read_u32_index for retrieval of individual values.

This makes it possible to remove the raw access to the states property entirely.

Signed-off-by: Heiko Stuebner <heiko.stuebner@bqreaders.com>
Acked-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Mark Brown <broonie@linaro.org>

authored by

Heiko Stuebner and committed by
Mark Brown
934624d6 b56fad85

+6 -9
+6 -9
drivers/regulator/gpio-regulator.c
··· 136 136 of_get_gpio_regulator_config(struct device *dev, struct device_node *np) 137 137 { 138 138 struct gpio_regulator_config *config; 139 - struct property *prop; 140 139 const char *regtype; 141 140 int proplen, gpio, i; 142 141 int ret; ··· 190 191 } 191 192 192 193 /* Fetch states. */ 193 - prop = of_find_property(np, "states", NULL); 194 - if (!prop) { 194 + proplen = of_property_count_u32_elems(np, "states"); 195 + if (proplen < 0) { 195 196 dev_err(dev, "No 'states' property found\n"); 196 197 return ERR_PTR(-EINVAL); 197 198 } 198 - 199 - proplen = prop->length / sizeof(int); 200 199 201 200 config->states = devm_kzalloc(dev, 202 201 sizeof(struct gpio_regulator_state) ··· 204 207 return ERR_PTR(-ENOMEM); 205 208 206 209 for (i = 0; i < proplen / 2; i++) { 207 - config->states[i].value = 208 - be32_to_cpup((int *)prop->value + (i * 2)); 209 - config->states[i].gpios = 210 - be32_to_cpup((int *)prop->value + (i * 2 + 1)); 210 + of_property_read_u32_index(np, "states", i * 2, 211 + &config->states[i].value); 212 + of_property_read_u32_index(np, "states", i * 2 + 1, 213 + &config->states[i].gpios); 211 214 } 212 215 config->nr_states = i; 213 216