regulator: userspace: use sysfs_create_group

and avoid introducing our own loops for creating
several sysfs entries.

Signed-off-by: Felipe Balbi <felipe.balbi@nokia.com>
Acked-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Acked-by: Mike Rapoport <mike@compulab.co.il>
Signed-off-by: Liam Girdwood <lrg@slimlogic.co.uk>
This commit is contained in:
Felipe Balbi 2009-08-10 09:05:13 +03:00 committed by Liam Girdwood
parent 86d9884b6a
commit e9d62698e8

View file

@ -93,16 +93,21 @@ static ssize_t reg_set_state(struct device *dev, struct device_attribute *attr,
static DEVICE_ATTR(name, 0444, reg_show_name, NULL); static DEVICE_ATTR(name, 0444, reg_show_name, NULL);
static DEVICE_ATTR(state, 0644, reg_show_state, reg_set_state); static DEVICE_ATTR(state, 0644, reg_show_state, reg_set_state);
static struct device_attribute *attributes[] = { static struct attribute *attributes[] = {
&dev_attr_name, &dev_attr_name.attr,
&dev_attr_state, &dev_attr_state.attr,
NULL,
};
static const struct attribute_group attr_group = {
.attrs = attributes,
}; };
static int regulator_userspace_consumer_probe(struct platform_device *pdev) static int regulator_userspace_consumer_probe(struct platform_device *pdev)
{ {
struct regulator_userspace_consumer_data *pdata; struct regulator_userspace_consumer_data *pdata;
struct userspace_consumer_data *drvdata; struct userspace_consumer_data *drvdata;
int ret, i; int ret;
pdata = pdev->dev.platform_data; pdata = pdev->dev.platform_data;
if (!pdata) if (!pdata)
@ -125,31 +130,29 @@ static int regulator_userspace_consumer_probe(struct platform_device *pdev)
goto err_alloc_supplies; goto err_alloc_supplies;
} }
for (i = 0; i < ARRAY_SIZE(attributes); i++) { ret = sysfs_create_group(&pdev->dev.kobj, &attr_group);
ret = device_create_file(&pdev->dev, attributes[i]); if (ret != 0)
if (ret != 0) goto err_create_attrs;
goto err_create_attrs;
}
if (pdata->init_on) if (pdata->init_on) {
ret = regulator_bulk_enable(drvdata->num_supplies, ret = regulator_bulk_enable(drvdata->num_supplies,
drvdata->supplies); drvdata->supplies);
if (ret) {
drvdata->enabled = pdata->init_on; dev_err(&pdev->dev,
"Failed to set initial state: %d\n", ret);
if (ret) { goto err_enable;
dev_err(&pdev->dev, "Failed to set initial state: %d\n", ret); }
goto err_create_attrs;
} }
drvdata->enabled = pdata->init_on;
platform_set_drvdata(pdev, drvdata); platform_set_drvdata(pdev, drvdata);
return 0; return 0;
err_create_attrs: err_enable:
for (i = 0; i < ARRAY_SIZE(attributes); i++) sysfs_remove_group(&pdev->dev.kobj, &attr_group);
device_remove_file(&pdev->dev, attributes[i]);
err_create_attrs:
regulator_bulk_free(drvdata->num_supplies, drvdata->supplies); regulator_bulk_free(drvdata->num_supplies, drvdata->supplies);
err_alloc_supplies: err_alloc_supplies:
@ -160,10 +163,8 @@ err_alloc_supplies:
static int regulator_userspace_consumer_remove(struct platform_device *pdev) static int regulator_userspace_consumer_remove(struct platform_device *pdev)
{ {
struct userspace_consumer_data *data = platform_get_drvdata(pdev); struct userspace_consumer_data *data = platform_get_drvdata(pdev);
int i;
for (i = 0; i < ARRAY_SIZE(attributes); i++) sysfs_remove_group(&pdev->dev.kobj, &attr_group);
device_remove_file(&pdev->dev, attributes[i]);
if (data->enabled) if (data->enabled)
regulator_bulk_disable(data->num_supplies, data->supplies); regulator_bulk_disable(data->num_supplies, data->supplies);