linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Inga Stotland <inga.stotland@intel.com>
To: linux-bluetooth@vger.kernel.org
Cc: brian.gix@intel.com, Inga Stotland <inga.stotland@intel.com>
Subject: [PATCH BlueZ 1/1] mesh: Remove redundant checks when adding a net key
Date: Tue, 11 Jun 2019 16:16:43 -0700	[thread overview]
Message-ID: <20190611231643.25165-1-inga.stotland@intel.com> (raw)

This patch cleans up redundant checks in sdd_key() and mesh_net_set_key():
no need to check the result of l_queue_push_tail() and not need to check
if subnet is valid after it was successfully created.
---
 mesh/net.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/mesh/net.c b/mesh/net.c
index fdd38e7ce..a597b8794 100644
--- a/mesh/net.c
+++ b/mesh/net.c
@@ -992,12 +992,13 @@ static struct mesh_subnet *add_key(struct mesh_net *net, uint16_t idx,
 		return NULL;
 	}
 
-	if (!create_secure_beacon(net, subnet, subnet->snb.beacon + 1) ||
-				!l_queue_push_tail(net->subnets, subnet)) {
+	if (!create_secure_beacon(net, subnet, subnet->snb.beacon + 1)) {
 		subnet_free(subnet);
 		return NULL;
 	}
 
+	l_queue_push_tail(net->subnets, subnet);
+
 	return subnet;
 }
 
@@ -3018,11 +3019,6 @@ bool mesh_net_set_key(struct mesh_net *net, uint16_t idx, const uint8_t *key,
 {
 	struct mesh_subnet *subnet;
 
-	subnet = l_queue_find(net->subnets, match_key_index,
-							L_UINT_TO_PTR(idx));
-	if (subnet)
-		return false;
-
 	/* Current key must be always present */
 	if (!key)
 		return false;
@@ -3031,12 +3027,13 @@ bool mesh_net_set_key(struct mesh_net *net, uint16_t idx, const uint8_t *key,
 	if (phase != KEY_REFRESH_PHASE_NONE && !new_key)
 		return false;
 
-	subnet = add_key(net, idx, key);
-	if (!subnet)
-		return false;
-
+	/* Check if the subnet with the specified index already exists */
 	subnet = l_queue_find(net->subnets, match_key_index,
 							L_UINT_TO_PTR(idx));
+	if (subnet)
+		return false;
+
+	subnet = add_key(net, idx, key);
 	if (!subnet)
 		return false;
 
-- 
2.21.0


             reply	other threads:[~2019-06-11 23:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-11 23:16 Inga Stotland [this message]
2019-06-12 21:38 ` [PATCH BlueZ 1/1] mesh: Remove redundant checks when adding a net key Gix, Brian

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190611231643.25165-1-inga.stotland@intel.com \
    --to=inga.stotland@intel.com \
    --cc=brian.gix@intel.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).