mesh: Fix check for mkdir return value in keyring.c
authorInga Stotland <inga.stotland@intel.com>
Tue, 22 Dec 2020 06:04:08 +0000 (11:34 +0530)
committerAbhay Agarwal <ay.agarwal@samsung.com>
Mon, 28 Dec 2020 06:20:04 +0000 (11:50 +0530)
Remove check for mkdir() return value, since checking for zero does not
cover "already exists" condition and adding extra check for errno value
unnecessarily complicates the code. If mkdir() fails due to any reason
than "already exists", the subsequent call to open() fails and the
error is detected and corectly processed by the code.

Change-Id: I72db1d9553ba9a8269d391f938fbb26abc5cdf50
Signed-off-by: Abhay Agarwal <ay.agarwal@samsung.com>
mesh/keyring.c
mesh/mesh.c
mesh/node.c

index 5add8bb222c77f88d124c4e33befee083874bcf2..3ae9314d926426ca36dbfd98d5b5c1af6da0c377 100644 (file)
@@ -52,8 +52,7 @@ bool keyring_put_net_key(struct mesh_node *node, uint16_t net_idx,
 
        snprintf(key_file, PATH_MAX, "%s%s", node_path, net_key_dir);
 
-       if (!mkdir(key_file, 0755))
-               l_debug("failed to mkdir %s", key_file);
+       mkdir(key_file, 0755);
 
        snprintf(key_file, PATH_MAX, "%s%s/%3.3x", node_path, net_key_dir,
                                                                net_idx);
@@ -89,8 +88,7 @@ bool keyring_put_app_key(struct mesh_node *node, uint16_t app_idx,
 
        snprintf(key_file, PATH_MAX, "%s%s", node_path, app_key_dir);
 
-       if (!mkdir(key_file, 0755))
-               l_debug("failed to mkdir %s", key_file);
+       mkdir(key_file, 0755);
 
        snprintf(key_file, PATH_MAX, "%s%s/%3.3x", node_path, app_key_dir,
                                                                app_idx);
@@ -208,8 +206,7 @@ bool keyring_put_remote_dev_key(struct mesh_node *node, uint16_t unicast,
 
        snprintf(key_file, PATH_MAX, "%s%s", node_path, dev_key_dir);
 
-       if (!mkdir(key_file, 0755))
-               l_debug("failed to mkdir %s", key_file);
+       mkdir(key_file, 0755);
 
        for (i = 0; i < count; i++) {
                snprintf(key_file, PATH_MAX, "%s%s/%4.4x", node_path,
index d8525d144a276de3bce2aa7b2180dbaf5dbd834f..890855a38c1b3a32ac00e6c43be14110f5e5144b 100644 (file)
@@ -482,7 +482,7 @@ static bool prov_complete_cb(void *user_data, uint8_t status,
 
        l_dbus_message_set_arguments(msg, "t", l_get_be64(token));
        dbus_send_with_timeout(dbus, msg, prov_join_complete_reply_cb,
-                                               NULL, NULL, DEFAULT_DBUS_TIMEOUT);
+                                       NULL, NULL, DEFAULT_DBUS_TIMEOUT);
 
        return true;
 }
@@ -742,7 +742,7 @@ static void create_join_complete_reply_cb(struct l_dbus_message *msg,
 {
        struct mesh_node *node = user_data;
 
-        if (!msg || l_dbus_message_is_error(msg)) {
+       if (!msg || l_dbus_message_is_error(msg)) {
                node_remove(node);
                return;
        }
@@ -787,7 +787,7 @@ static void create_node_ready_cb(void *user_data, int status,
 
        l_dbus_message_set_arguments(msg, "t", l_get_be64(token));
        dbus_send_with_timeout(dbus, msg, create_join_complete_reply_cb,
-                                               node, NULL, DEFAULT_DBUS_TIMEOUT);
+                                       node, NULL, DEFAULT_DBUS_TIMEOUT);
        l_dbus_message_unref(pending_msg);
 }
 
index d2e420e88bcf9f31f195f667bf4fe3dd0845b375..0cca4c8d21330261109dd5425ba0d53c07fe5af7 100644 (file)
@@ -18,6 +18,7 @@
 #include <dirent.h>
 #include <stdio.h>
 #include <sys/time.h>
+
 #include <ell/ell.h>
 
 #include "mesh/mesh-defs.h"