aboutsummaryrefslogtreecommitdiff
path: root/regulator.c
diff options
context:
space:
mode:
authorDaniel Lezcano <daniel.lezcano@free.fr>2011-03-26 22:05:53 +0100
committerAmit Kucheria <amit.kucheria@linaro.org>2011-04-04 02:18:30 +0300
commit4aab2fe72886682b18a5000f655530bded6bafb8 (patch)
tree89c5c7dfca00a004aa3a743919e80196050f839f /regulator.c
parentf45321e4107460827e7b80289285954cf350d9d0 (diff)
downloadpowerdebug-4aab2fe72886682b18a5000f655530bded6bafb8.tar.gz
make regulator_init to return a regulators_info pointer
The regulator_init function does no longer use the global defined function. Signed-off-by: Daniel Lezcano <daniel.lezcano@free.fr> Signed-off-by: Amit Kucheria <amit.kucheria@linaro.org>
Diffstat (limited to 'regulator.c')
-rw-r--r--regulator.c18
1 files changed, 6 insertions, 12 deletions
diff --git a/regulator.c b/regulator.c
index 91c3903..ddbeea3 100644
--- a/regulator.c
+++ b/regulator.c
@@ -17,15 +17,17 @@
#define SYSFS_REGULATOR "/sys/class/regulator"
-int regulator_init(void)
+struct regulator_info *regulator_init(int *nr_regulators)
{
DIR *regdir;
struct dirent *item;
+ *nr_regulators = 0;
+
regdir = opendir(SYSFS_REGULATOR);
if (!regdir) {
fprintf(stderr, "failed to open '%s': %m\n", SYSFS_REGULATOR);
- return -1;
+ return NULL;
}
while ((item = readdir(regdir))) {
@@ -36,20 +38,12 @@ int regulator_init(void)
if (!strcmp(item->d_name, ".."))
continue;
- numregulators++;
+ (*nr_regulators)++;
}
closedir(regdir);
- regulators_info = (struct regulator_info *)malloc(numregulators*
- sizeof(struct regulator_info));
- if (!regulators_info) {
- fprintf(stderr, "init_regulator_ds: Not enough memory to "
- "read information for %d regulators!\n", numregulators);
- return(1);
- }
-
- return(0);
+ return malloc(*nr_regulators * sizeof(struct regulator_info));
}
static void print_string_val(char *name, char *val)