regulator: core: optimize devm_regulator_bulk_get()

When performing this bulk operation, there is no need to track every supply
individually. It is more efficient to treat entire group as a single
managed resource.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
Dmitry Torokhov 2017-02-03 15:16:18 -08:00 committed by Mark Brown
parent b8c77ff690
commit 3eaeb47563

View File

@ -120,6 +120,18 @@ void devm_regulator_put(struct regulator *regulator)
} }
EXPORT_SYMBOL_GPL(devm_regulator_put); EXPORT_SYMBOL_GPL(devm_regulator_put);
struct regulator_bulk_devres {
struct regulator_bulk_data *consumers;
int num_consumers;
};
static void devm_regulator_bulk_release(struct device *dev, void *res)
{
struct regulator_bulk_devres *devres = res;
regulator_bulk_free(devres->num_consumers, devres->consumers);
}
/** /**
* devm_regulator_bulk_get - managed get multiple regulator consumers * devm_regulator_bulk_get - managed get multiple regulator consumers
* *
@ -138,30 +150,23 @@ EXPORT_SYMBOL_GPL(devm_regulator_put);
int devm_regulator_bulk_get(struct device *dev, int num_consumers, int devm_regulator_bulk_get(struct device *dev, int num_consumers,
struct regulator_bulk_data *consumers) struct regulator_bulk_data *consumers)
{ {
int i; struct regulator_bulk_devres *devres;
int ret; int ret;
for (i = 0; i < num_consumers; i++) devres = devres_alloc(devm_regulator_bulk_release,
consumers[i].consumer = NULL; sizeof(*devres), GFP_KERNEL);
if (!devres)
return -ENOMEM;
for (i = 0; i < num_consumers; i++) { ret = regulator_bulk_get(dev, num_consumers, consumers);
consumers[i].consumer = devm_regulator_get(dev, if (!ret) {
consumers[i].supply); devres->consumers = consumers;
if (IS_ERR(consumers[i].consumer)) { devres->num_consumers = num_consumers;
ret = PTR_ERR(consumers[i].consumer); devres_add(dev, devres);
dev_err(dev, "Failed to get supply '%s': %d\n", } else {
consumers[i].supply, ret); devres_free(devres);
consumers[i].consumer = NULL;
goto err;
}
} }
return 0;
err:
for (i = 0; i < num_consumers && consumers[i].consumer; i++)
devm_regulator_put(consumers[i].consumer);
return ret; return ret;
} }
EXPORT_SYMBOL_GPL(devm_regulator_bulk_get); EXPORT_SYMBOL_GPL(devm_regulator_bulk_get);