net: lwm2m: improve return errors from update_attrs()

When any error is returned from update_attrs() in engine_add_observer()
an EINVAL is returned back to the caller.  Let's return whatever error
code was generated in update_attrs() instead.

Also, add handling where previously errors were ignored.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
This commit is contained in:
Michael Scott 2018-05-07 14:18:37 -07:00 committed by Jukka Rissanen
commit 573c1f777e

View file

@ -406,7 +406,7 @@ static int engine_add_observer(struct lwm2m_message *msg,
.pmin = DEFAULT_SERVER_PMIN, .pmin = DEFAULT_SERVER_PMIN,
.pmax = DEFAULT_SERVER_PMAX, .pmax = DEFAULT_SERVER_PMAX,
}; };
int i; int i, ret;
if (!msg || !msg->ctx) { if (!msg || !msg->ctx) {
SYS_LOG_ERR("valid lwm2m message is required"); SYS_LOG_ERR("valid lwm2m message is required");
@ -451,8 +451,9 @@ static int engine_add_observer(struct lwm2m_message *msg,
return -ENOENT; return -ENOENT;
} }
if (update_attrs(&obj->attr_list, &attrs) < 0) { ret = update_attrs(&obj->attr_list, &attrs);
return -EINVAL; if (ret < 0) {
return ret;
} }
/* check if object instance exists */ /* check if object instance exists */
@ -465,8 +466,9 @@ static int engine_add_observer(struct lwm2m_message *msg,
return -ENOENT; return -ENOENT;
} }
if (update_attrs(&obj_inst->attr_list, &attrs) < 0) { ret = update_attrs(&obj_inst->attr_list, &attrs);
return -EINVAL; if (ret < 0) {
return ret;
} }
} }
@ -485,9 +487,9 @@ static int engine_add_observer(struct lwm2m_message *msg,
return -ENOENT; return -ENOENT;
} }
if (update_attrs(&obj_inst->resources[i].attr_list, ret = update_attrs(&obj_inst->resources[i].attr_list, &attrs);
&attrs) < 0) { if (ret < 0) {
return -EINVAL; return ret;
} }
} }
@ -2263,7 +2265,10 @@ static int lwm2m_write_attr_handler(struct lwm2m_engine_obj *obj,
} }
/* retrieve existing attributes */ /* retrieve existing attributes */
update_attrs(attr_list, &nattrs); ret = update_attrs(attr_list, &nattrs);
if (ret < 0) {
return ret;
}
/* loop through options to parse attribute */ /* loop through options to parse attribute */
for (int i = 0; i < nr_opt; i++) { for (int i = 0; i < nr_opt; i++) {
@ -2471,7 +2476,10 @@ static int lwm2m_write_attr_handler(struct lwm2m_engine_obj *obj,
nattrs.pmin = DEFAULT_SERVER_PMIN; nattrs.pmin = DEFAULT_SERVER_PMIN;
nattrs.pmax = DEFAULT_SERVER_PMAX; nattrs.pmax = DEFAULT_SERVER_PMAX;
update_attrs(&obj->attr_list, &nattrs); ret = update_attrs(&obj->attr_list, &nattrs);
if (ret < 0) {
return ret;
}
if (obs->path.level > 1) { if (obs->path.level > 1) {
if (path->level > 1 && if (path->level > 1 &&
@ -2490,7 +2498,10 @@ static int lwm2m_write_attr_handler(struct lwm2m_engine_obj *obj,
} }
} }
update_attrs(&obj_inst->attr_list, &nattrs); ret = update_attrs(&obj_inst->attr_list, &nattrs);
if (ret < 0) {
return ret;
}
} }
if (obs->path.level > 2) { if (obs->path.level > 2) {
@ -2507,7 +2518,10 @@ static int lwm2m_write_attr_handler(struct lwm2m_engine_obj *obj,
} }
} }
update_attrs(&res->attr_list, &nattrs); ret = update_attrs(&res->attr_list, &nattrs);
if (ret < 0) {
return ret;
}
} }
SYS_LOG_DBG("%d/%d/%d(%d) updated from %d/%d to %u/%u", SYS_LOG_DBG("%d/%d/%d(%d) updated from %d/%d to %u/%u",