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/2] mesh: Make "elements" mandatory in node configuration
Date: Wed, 5 Jun 2019 18:18:31 -0700 [thread overview]
Message-ID: <20190606011832.18801-2-inga.stotland@intel.com> (raw)
In-Reply-To: <20190606011832.18801-1-inga.stotland@intel.com>
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
next prev parent reply other threads:[~2019-06-06 1:18 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-06 1:18 [PATCH BlueZ 0/2] Minor fixes and clean up Inga Stotland
2019-06-06 1:18 ` Inga Stotland [this message]
2019-06-06 1:18 ` [PATCH BlueZ 2/2] mesh: Clean up style Inga Stotland
2019-06-06 19:32 ` [PATCH BlueZ 0/2] Minor fixes and clean up 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=20190606011832.18801-2-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).