Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp7451197ybi; Wed, 5 Jun 2019 18:20:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqxm2eoNCRL2NputXw3zCe+FjumhBnSxicGls3X5rQINsnL4fBNz5oi13DDnOKjXFHCE/7lN X-Received: by 2002:a17:902:9b94:: with SMTP id y20mr32746221plp.260.1559784044218; Wed, 05 Jun 2019 18:20:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559784044; cv=none; d=google.com; s=arc-20160816; b=d9lg44PG17Ye4qs75OO/I2VWCXO+9RZQd2b6Mzg+V9SgGh0IxjI+XXeMjuLSZaS6tQ bIurxsfx3cPdRus6d++kH4c5zRwfz9UvCXNfDLNrv53yvpymMm+dsF/ugT4i7WGVMiBZ W9clmFtQ96PSy0FfGCEHwZpRR0sa42DjsPS9l/U5ATEK3woZx6V+AGEqp7RZfDWORmLs CCOjwIieuhknf1DtQz050hVHg41+UqIz9q9mrCaonFteU/XrcfuAzkwSjxr7+gald/j/ iNlkN93nqYMPjlrDqyZnEXJtKWrUBX9pHDzQ8gdrI4Bf2ILm7b4lfRO4nnpVdf7tMAeU MoPw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=rfHqqRr2WsGnIvK1oeczjaRKlkKK1nXDag+rfJGYyt0=; b=AJaqwrUjpAhwk+TCdfeKn8paUYZkKc/7FbxH1WLd2pv1yz5f9+7ILqYi1GItz4HjG7 Il6X7L7ZXmwI9RbigZxRFoq605Q9BWZzW8poswzD2DBCnhuesSKSJyHWl932G5qnOHlB 6pdEI5dmVCjtLCzyMoANUoTI77ZOGeWOlEti0ADLJMk9p7nVSjW+K6P4r2Q+qpvjdsvP Y3gHH4jkPRXRdaYDx2A4E8kza3gbzwgaxd3QGlm1QKTZiwmHQVKETld2T7aznHo+tq96 h6qFs6CC5PwUylx6LjEKVTkw5q3WxMImQHtq26+98ZefCI4KWH72ge5zaXlmnjOHvtJo fPVw== 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 a190si237789pfb.122.2019.06.05.18.20.29; Wed, 05 Jun 2019 18:20:44 -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 S1726532AbfFFBSg (ORCPT + 99 others); Wed, 5 Jun 2019 21:18:36 -0400 Received: from mga11.intel.com ([192.55.52.93]:54825 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726593AbfFFBSg (ORCPT ); Wed, 5 Jun 2019 21:18:36 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Jun 2019 18:18:36 -0700 X-ExtLoop1: 1 Received: from ingas-nuc1.sea.intel.com ([10.251.155.118]) by orsmga003.jf.intel.com with ESMTP; 05 Jun 2019 18:18:35 -0700 From: Inga Stotland To: linux-bluetooth@vger.kernel.org Cc: brian.gix@intel.com, Inga Stotland Subject: [PATCH BlueZ 1/2] mesh: Make "elements" mandatory in node configuration Date: Wed, 5 Jun 2019 18:18:31 -0700 Message-Id: <20190606011832.18801-2-inga.stotland@intel.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190606011832.18801-1-inga.stotland@intel.com> References: <20190606011832.18801-1-inga.stotland@intel.com> 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 modifies the behavior of node configuration parsing: if "elements" property is not present, th configuration file for this node is regarded as malformed. Also, clean up style. --- mesh/mesh-db.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/mesh/mesh-db.c b/mesh/mesh-db.c index 5b2868fdb..e0a000261 100644 --- a/mesh/mesh-db.c +++ b/mesh/mesh-db.c @@ -767,8 +767,6 @@ static bool parse_bindings(json_object *jbindings, struct mesh_db_model *mod) return true; mod->bindings = l_new(uint16_t, cnt); - if (!mod->bindings) - return false; for (i = 0; i < cnt; ++i) { int idx; @@ -879,8 +877,6 @@ static bool parse_model_subscriptions(json_object *jsubs, return true; subs = l_new(struct mesh_db_sub, cnt); - if (!subs) - return false; for (i = 0; i < cnt; ++i) { char *str; @@ -996,14 +992,15 @@ static bool parse_elements(json_object *jelements, struct mesh_db_node *node) { int i, num_ele; + if (json_object_get_type(jelements) != json_type_array) + return false; + num_ele = json_object_array_length(jelements); if (!num_ele) /* Allow "empty" nodes */ return true; node->elements = l_queue_new(); - if (!node->elements) - return false; for (i = 0; i < num_ele; ++i) { json_object *jelement; @@ -1024,8 +1021,6 @@ static bool parse_elements(json_object *jelements, struct mesh_db_node *node) ele = l_new(struct mesh_db_element, 1); ele->index = index; ele->models = l_queue_new(); - if (!ele->models) - goto fail; if (!json_object_object_get_ex(jelement, "location", &jvalue)) goto fail; @@ -1209,12 +1204,12 @@ bool mesh_db_read_node(json_object *jnode, mesh_db_node_cb cb, void *user_data) if (json_object_object_get_ex(jnode, "sequenceNumber", &jvalue)) node.seq_number = json_object_get_int(jvalue); - if (json_object_object_get_ex(jnode, "elements", &jvalue)) { - if (json_object_get_type(jvalue) == json_type_array) { - if (!parse_elements(jvalue, &node)) - return false; - } - } + /* Check for required "elements" property */ + if (!json_object_object_get_ex(jnode, "elements", &jvalue)) + return false; + + if (!parse_elements(jvalue, &node)) + return false; return cb(&node, user_data); } -- 2.21.0