All the files found in the /sys/class/regulator directory should
be regulators. Don't assume their name begin with 'regulator'.

Signed-off-by: Daniel Lezcano <daniel.lezc...@free.fr>
---
 regulator.c |   18 ++++++++++++++----
 1 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/regulator.c b/regulator.c
index 255a56d..342a1a7 100644
--- a/regulator.c
+++ b/regulator.c
@@ -15,20 +15,30 @@
 
 #include "regulator.h"
 
+#define SYSFS_REGULATOR "/sys/class/regulator"
+
 int regulator_init(void)
 {
        DIR *regdir;
        struct dirent *item;
 
-       regdir = opendir("/sys/class/regulator");
-       if (!regdir)
-               return(1);
+       regdir = opendir(SYSFS_REGULATOR);
+       if (!regdir) {
+               fprintf(stderr, "failed to open '%s': %m\n", SYSFS_REGULATOR);
+               return -1;
+       }
+
        while ((item = readdir(regdir))) {
-               if (strncmp(item->d_name, "regulator", 9))
+
+               if (!strcmp(item->d_name, "."))
+                       continue;
+
+               if (!strcmp(item->d_name, ".."))
                        continue;
 
                numregulators++;
        }
+
        closedir(regdir);
 
        regulators_info = (struct regulator_info *)malloc(numregulators*
-- 
1.7.1


_______________________________________________
linaro-dev mailing list
linaro-dev@lists.linaro.org
http://lists.linaro.org/mailman/listinfo/linaro-dev

Reply via email to