From 59ef3ef041ad1ec080c54ea2c784f546c73d35b6 Mon Sep 17 00:00:00 2001 From: Inga Stotland Date: Tue, 22 Dec 2020 11:34:08 +0530 Subject: [PATCH] mesh: Fix check for mkdir return value in keyring.c 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 --- mesh/keyring.c | 9 +++------ mesh/mesh.c | 6 +++--- mesh/node.c | 1 + 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/mesh/keyring.c b/mesh/keyring.c index 5add8bb..3ae9314 100644 --- a/mesh/keyring.c +++ b/mesh/keyring.c @@ -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, diff --git a/mesh/mesh.c b/mesh/mesh.c index d8525d1..890855a 100644 --- a/mesh/mesh.c +++ b/mesh/mesh.c @@ -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); } diff --git a/mesh/node.c b/mesh/node.c index d2e420e..0cca4c8 100644 --- a/mesh/node.c +++ b/mesh/node.c @@ -18,6 +18,7 @@ #include #include #include + #include #include "mesh/mesh-defs.h" -- 2.7.4