Linux-Bluetooth Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH BlueZ 1/1] mesh: Remove redundant checks when adding a net key
@ 2019-06-11 23:16 Inga Stotland
  2019-06-12 21:38 ` Gix, Brian
  0 siblings, 1 reply; 2+ messages in thread
From: Inga Stotland @ 2019-06-11 23:16 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: brian.gix, Inga Stotland

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH BlueZ 1/1] mesh: Remove redundant checks when adding a net key
  2019-06-11 23:16 [PATCH BlueZ 1/1] mesh: Remove redundant checks when adding a net key Inga Stotland
@ 2019-06-12 21:38 ` Gix, Brian
  0 siblings, 0 replies; 2+ messages in thread
From: Gix, Brian @ 2019-06-12 21:38 UTC (permalink / raw)
  To: linux-bluetooth, Stotland, Inga

Applied with minor commit message tweeks

On Tue, 2019-06-11 at 16:16 -0700, Inga Stotland wrote:
> 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;
>  

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-11 23:16 [PATCH BlueZ 1/1] mesh: Remove redundant checks when adding a net key Inga Stotland
2019-06-12 21:38 ` Gix, Brian

Linux-Bluetooth Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-bluetooth/0 linux-bluetooth/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-bluetooth linux-bluetooth/ https://lore.kernel.org/linux-bluetooth \
		linux-bluetooth@vger.kernel.org linux-bluetooth@archiver.kernel.org
	public-inbox-index linux-bluetooth


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-bluetooth


AGPL code for this site: git clone https://public-inbox.org/ public-inbox