udevtrigger: reduce indent level in scan_* functions
authorGabor Juhos <juhosg@openwrt.org>
Tue, 10 Sep 2013 10:59:25 +0000 (12:59 +0200)
committerFelix Fietkau <nbd@openwrt.org>
Tue, 10 Sep 2013 11:25:35 +0000 (13:25 +0200)
Return early from the scan_* functions if the
opendir call fails. This allows to reduce the
indentation level of the subsequent code by
one tab.

Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
udevtrigger.c

index 98b074349ab45c889f911e80e92e8c8182fad7d0..dbb414ab7d561822b8584baacbe123b17b17e288 100644 (file)
@@ -185,20 +185,19 @@ static void scan_subdir(const char *base)
        struct dirent *dent;
 
        dir = opendir(base);
-       if (dir != NULL) {
-               for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
-                       char dirname[PATH_SIZE];
+       if (dir == NULL)
+               return;
 
-                       if (dent->d_name[0] == '.')
-                               continue;
+       for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
+               char dirname[PATH_SIZE];
 
-                       strlcpy(dirname, base, sizeof(dirname));
-                       strlcat(dirname, "/", sizeof(dirname));
-                       strlcat(dirname, dent->d_name, sizeof(dirname));
-                       device_list_insert(dirname);
-               }
-               closedir(dir);
+               strlcpy(dirname, base, sizeof(dirname));
+               strlcat(dirname, "/", sizeof(dirname));
+               strlcat(dirname, dent->d_name, sizeof(dirname));
+               device_list_insert(dirname);
        }
+
+       closedir(dir);
 }
 
 static void scan_subsystem(const char *subsys)
@@ -211,23 +210,25 @@ static void scan_subsystem(const char *subsys)
        strlcat(base, subsys, sizeof(base));
 
        dir = opendir(base);
-       if (dir != NULL) {
-               for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
-                       char dirname[PATH_SIZE];
+       if (dir == NULL)
+               return;
 
-                       if (dent->d_name[0] == '.')
-                               continue;
+       for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
+               char dirname[PATH_SIZE];
 
-                       strlcpy(dirname, base, sizeof(dirname));
-                       strlcat(dirname, "/", sizeof(dirname));
-                       strlcat(dirname, dent->d_name, sizeof(dirname));
-                       strlcat(dirname, "/devices", sizeof(dirname));
+               if (dent->d_name[0] == '.')
+                       continue;
 
-                       /* look for devices */
-                       scan_subdir(dirname);
-               }
-               closedir(dir);
+               strlcpy(dirname, base, sizeof(dirname));
+               strlcat(dirname, "/", sizeof(dirname));
+               strlcat(dirname, dent->d_name, sizeof(dirname));
+               strlcat(dirname, "/devices", sizeof(dirname));
+
+               /* look for devices */
+               scan_subdir(dirname);
        }
+
+       closedir(dir);
 }
 
 static void scan_block(void)
@@ -239,24 +240,26 @@ static void scan_block(void)
        strlcpy(base, "/sys/block", sizeof(base));
 
        dir = opendir(base);
-       if (dir != NULL) {
-               for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
-                       char dirname[PATH_SIZE];
+       if (dir == NULL)
+               return;
 
-                       if (dent->d_name[0] == '.')
-                               continue;
+       for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
+               char dirname[PATH_SIZE];
 
-                       strlcpy(dirname, base, sizeof(dirname));
-                       strlcat(dirname, "/", sizeof(dirname));
-                       strlcat(dirname, dent->d_name, sizeof(dirname));
-                       if (device_list_insert(dirname) != 0)
-                               continue;
+               if (dent->d_name[0] == '.')
+                       continue;
 
-                       /* look for partitions */
-                       scan_subdir(dirname);
-               }
-               closedir(dir);
+               strlcpy(dirname, base, sizeof(dirname));
+               strlcat(dirname, "/", sizeof(dirname));
+               strlcat(dirname, dent->d_name, sizeof(dirname));
+               if (device_list_insert(dirname) != 0)
+                       continue;
+
+               /* look for partitions */
+               scan_subdir(dirname);
        }
+
+       closedir(dir);
 }
 
 static void scan_class(void)
@@ -268,21 +271,23 @@ static void scan_class(void)
        strlcpy(base, "/sys/class", sizeof(base));
 
        dir = opendir(base);
-       if (dir != NULL) {
-               for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
-                       char dirname[PATH_SIZE];
+       if (dir == NULL)
+               return;
 
-                       if (dent->d_name[0] == '.')
-                               continue;
+       for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
+               char dirname[PATH_SIZE];
 
-                       strlcpy(dirname, base, sizeof(dirname));
-                       strlcat(dirname, "/", sizeof(dirname));
-                       strlcat(dirname, dent->d_name, sizeof(dirname));
+               if (dent->d_name[0] == '.')
+                       continue;
 
-                       scan_subdir(dirname);
-               }
-               closedir(dir);
+               strlcpy(dirname, base, sizeof(dirname));
+               strlcat(dirname, "/", sizeof(dirname));
+               strlcat(dirname, dent->d_name, sizeof(dirname));
+
+               scan_subdir(dirname);
        }
+
+       closedir(dir);
 }
 
 int main(int argc, char *argv[], char *envp[])