Cleanup coding style. Don't check the return values of l_new() and l_queue_new().
Add check for the presense of "elements" property in node configuration
(it's mandatory)
Inga Stotland (2):
mesh: Make "elements" mandatory in node configuration
mesh: Clean up style
mesh/mesh-db.c | 23 +++++++++--------------
mesh/model.c | 25 +++++++++++++------------
2 files changed, 22 insertions(+), 26 deletions(-)
--
2.21.0
This cleans up some stylistic issues. Plus, don't check the return
value of l_new(): if memory allocation fails, the execution stops.
---
mesh/model.c | 25 +++++++++++++------------
1 file changed, 13 insertions(+), 12 deletions(-)
diff --git a/mesh/model.c b/mesh/model.c
index 90bb62db8..f29ad9af2 100644
--- a/mesh/model.c
+++ b/mesh/model.c
@@ -158,9 +158,7 @@ static struct mesh_model *get_model(struct mesh_node *node, uint8_t ele_idx,
model = l_queue_find(models, match_model_id, L_UINT_TO_PTR(id));
- if (status)
- *status = (model) ? MESH_STATUS_SUCCESS :
- MESH_STATUS_INVALID_MODEL;
+ *status = (model) ? MESH_STATUS_SUCCESS : MESH_STATUS_INVALID_MODEL;
return model;
}
@@ -605,10 +603,8 @@ static int set_pub(struct mesh_model *mod, const uint8_t *mod_addr,
*dst = l_get_le16(mod_addr);
}
- if (b_virt) {
- if (!mesh_crypto_virtual_addr(mod_addr, &grp))
- return MESH_STATUS_STORAGE_FAIL;
- }
+ if (b_virt && !mesh_crypto_virtual_addr(mod_addr, &grp))
+ return MESH_STATUS_STORAGE_FAIL;
/* If old publication was Virtual, remove it */
if (mod->pub && mod->pub->addr >= VIRTUAL_BASE) {
@@ -621,6 +617,7 @@ static int set_pub(struct mesh_model *mod, const uint8_t *mod_addr,
}
mod->pub = l_new(struct mesh_model_pub, 1);
+
if (b_virt) {
virt = l_queue_find(mesh_virtuals, find_virt_by_addr, mod_addr);
if (!virt) {
@@ -632,6 +629,7 @@ static int set_pub(struct mesh_model *mod, const uint8_t *mod_addr,
} else {
grp = virt->ota;
}
+
virt->ref_cnt++;
l_queue_push_head(mod->virtuals, virt);
mod->pub->addr = virt->id;
@@ -648,10 +646,9 @@ static int set_pub(struct mesh_model *mod, const uint8_t *mod_addr,
mod->pub = NULL;
/* Remove publication if Pub Addr is 0x0000 */
} else {
+
if (!mod->pub)
mod->pub = l_new(struct mesh_model_pub, 1);
- if (!mod->pub)
- return MESH_STATUS_STORAGE_FAIL;
mod->pub->credential = cred_flag;
mod->pub->idx = idx;
@@ -679,11 +676,13 @@ static int add_sub(struct mesh_net *net, struct mesh_model *mod,
virt->id = virt_id_next++;
virt->ota = grp;
memcpy(virt->addr, group, sizeof(virt->addr));
+
if (!l_queue_push_head(mesh_virtuals, virt))
return MESH_STATUS_STORAGE_FAIL;
} else {
grp = virt->ota;
}
+
virt->ref_cnt++;
l_queue_push_head(mod->virtuals, virt);
} else {
@@ -1125,11 +1124,12 @@ bool mesh_model_register(struct mesh_node *node, uint8_t ele_idx,
void *user_data)
{
struct mesh_model *mod;
+ int status;
/* Internal models are always SIG models */
mod_id = VENDOR_ID_MASK | mod_id;
- mod = get_model(node, ele_idx, mod_id, NULL);
+ mod = get_model(node, ele_idx, mod_id, &status);
if (!mod)
return false;
@@ -1206,6 +1206,7 @@ int mesh_model_get_bindings(struct mesh_node *node, uint16_t addr, uint32_t id,
buf += 3;
n += 3;
}
+
i++;
}
@@ -1318,6 +1319,7 @@ int mesh_model_sub_ovr(struct mesh_node *node, uint16_t addr, uint32_t id,
struct mesh_net *net = node_get_net(node);
entry = l_queue_get_entries(subs);
+
for (; entry; entry = entry->next)
mesh_net_dst_unreg(net,
(uint16_t) L_PTR_TO_UINT(entry->data));
@@ -1376,6 +1378,7 @@ int mesh_model_sub_del_all(struct mesh_node *node, uint16_t addr, uint32_t id)
return fail;
entry = l_queue_get_entries(mod->subs);
+
for (; entry; entry = entry->next)
mesh_net_dst_unreg(net, (uint16_t) L_PTR_TO_UINT(entry->data));
@@ -1548,8 +1551,6 @@ void mesh_model_add_virtual(struct mesh_node *node, const uint8_t *v)
}
virt = l_new(struct mesh_virtual, 1);
- if (!virt)
- return;
if (!mesh_crypto_virtual_addr(v, &virt->ota)) {
l_free(virt);
--
2.21.0
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
Patches Applied
On Wed, 2019-06-05 at 18:18 -0700, Inga Stotland wrote:
> Cleanup coding style. Don't check the return values of l_new() and
> l_queue_new().
> Add check for the presense of "elements" property in node
> configuration
> (it's mandatory)
>
> Inga Stotland (2):
> mesh: Make "elements" mandatory in node configuration
> mesh: Clean up style
>
> mesh/mesh-db.c | 23 +++++++++--------------
> mesh/model.c | 25 +++++++++++++------------
> 2 files changed, 22 insertions(+), 26 deletions(-)
>