Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp5303346ybi; Tue, 11 Jun 2019 23:50:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqyB5Uc9js3AmRRnevqOOJLAm5WW813qSLA8nBIElTaDSPNsGAh6XPRCsbhoh2FKpQwUaYRa X-Received: by 2002:a17:902:23:: with SMTP id 32mr18551543pla.34.1560322205738; Tue, 11 Jun 2019 23:50:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560322205; cv=none; d=google.com; s=arc-20160816; b=mcUANg09qotZrAc9NoGQuXrKubmJopzZv2lwp3BcxFMpRO7jSPqFndvHUjJ8njRHs0 iJZKgbYYogMTYq1O254LaaTAxWqhBqBGRKCR8++VG0Y7V3g5ZsUv50QiyM07G7pTIlqI YcjvPn74dinq20R62DMOshzpbH/zBAQsgptgOjO2zK9DjSK3rlMzVZqkiCyNZ++uzDpC Id6GBfpolY1NCNVBqaUCB3hJp5EsOkU6KpKf0/7+MMzzB2MBjJFZCfPTuPh5F9Ieb4dU DWPV9ZP9bqZvUUYGaKakteMJe+WUJC6zs2v4O9WvLPAKA5rAdtMn/Pn5yzLONINoXlhk ljmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=bKTE/7gEiBA2Td0ax4oIlEnJ2J/D7kcE/W0j5Uyw8DI=; b=lReHtwxiFHemclGy/TmHg2j9WX3ILG21JCAXxBJIRAONLn8CACBbkJq9iXSRXuTJD5 O/bBvXNJJlOGoOvfxkLkga4bc1NzVlqES5HaV4QNVGlj3SJuNJCRy1sRIxVpPRW3EYxx sp3ZZDBy0sa9I6XQo4A+2vzuKGOk0EnHAVuy8Bm+rSc3wQjZZ+70M4vBdGu51dXap3iK OVERMaJe5Qi5E/iA9i92QrzaVSUtKZ2p4Y4k9UAUEogfVFYosHtN8Of8bDcW1Jta6dOp bGHnhHwNluBGgN+eaDKEvvMIPLkJyxad7T9Vlmyn0njaXVvh40TmDLZa1OlUsHlFEbbO /WuQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q22si14970084pgl.309.2019.06.11.23.49.35; Tue, 11 Jun 2019 23:50:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405818AbfFKXQp (ORCPT + 99 others); Tue, 11 Jun 2019 19:16:45 -0400 Received: from mga03.intel.com ([134.134.136.65]:24911 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728264AbfFKXQp (ORCPT ); Tue, 11 Jun 2019 19:16:45 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Jun 2019 16:16:44 -0700 X-ExtLoop1: 1 Received: from drenteri-mobl1.amr.corp.intel.com (HELO ingas-nuc1.sea.intel.com) ([10.252.193.193]) by orsmga005.jf.intel.com with ESMTP; 11 Jun 2019 16:16:44 -0700 From: Inga Stotland To: linux-bluetooth@vger.kernel.org Cc: brian.gix@intel.com, Inga Stotland Subject: [PATCH BlueZ 1/1] mesh: Remove redundant checks when adding a net key Date: Tue, 11 Jun 2019 16:16:43 -0700 Message-Id: <20190611231643.25165-1-inga.stotland@intel.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org 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