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

regulator: gpio-regulator: fix forgotten gpios-states reading

Commit 934624d6e9f0 ("regulator: gpio-regulator: do not open-code counting
and access of dt array elements") forgot to convert the recently added
gpios-states property using the same pattern.

Convert this instance to use the of-helpers too, resolving the build error.

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

authored by

Heiko Stuebner and committed by
Mark Brown
1f5a9623 934624d6

+13 -9
+13 -9
drivers/regulator/gpio-regulator.c
··· 171 171 if (!config->gpios) 172 172 return ERR_PTR(-ENOMEM); 173 173 174 - prop = of_find_property(np, "gpios-states", NULL); 175 - if (prop) { 176 - proplen = prop->length / sizeof(int); 177 - if (proplen != config->nr_gpios) { 178 - dev_warn(dev, "gpios <-> gpios-states mismatch\n"); 179 - prop = NULL; 180 - } 174 + proplen = of_property_count_u32_elems(np, "gpios-states"); 175 + /* optional property */ 176 + if (proplen < 0) 177 + proplen = 0; 178 + 179 + if (proplen > 0 && proplen != config->nr_gpios) { 180 + dev_warn(dev, "gpios <-> gpios-states mismatch\n"); 181 + proplen = 0; 181 182 } 182 183 183 184 for (i = 0; i < config->nr_gpios; i++) { ··· 186 185 if (gpio < 0) 187 186 break; 188 187 config->gpios[i].gpio = gpio; 189 - if (prop && be32_to_cpup((int *)prop->value + i)) 190 - config->gpios[i].flags = GPIOF_OUT_INIT_HIGH; 188 + if (proplen > 0) { 189 + of_property_read_u32_index(np, "gpios-states", i, &ret); 190 + if (ret) 191 + config->gpios[i].flags = GPIOF_OUT_INIT_HIGH; 192 + } 191 193 } 192 194 193 195 /* Fetch states. */