Skip to content

Commit e426116

Browse files
mike-scottnashif
authored andcommitted
net: lwm2m: in oma_tlv_put don't re-add value when insert is true
We set "insert" to true when the value is already in the buffer, but we need to insert a TLV to denote things like RESOURCE_INSTANCE or OBJECT_INSTANCE. In this case, let's not re-add the value. Signed-off-by: Michael Scott <[email protected]>
1 parent 7345023 commit e426116

File tree

1 file changed

+8
-19
lines changed

1 file changed

+8
-19
lines changed

subsys/net/lib/lwm2m/lwm2m_rw_oma_tlv.c

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -205,25 +205,14 @@ static size_t oma_tlv_put(const struct oma_tlv *tlv,
205205
}
206206

207207
/* finally add the value */
208-
if (value != NULL && tlv->length > 0) {
209-
if (insert) {
210-
if (!net_pkt_insert(out->out_cpkt->pkt, out->frag,
211-
out->offset, tlv->length, value,
212-
BUF_ALLOC_TIMEOUT)) {
213-
/* TODO: Generate error? */
214-
return 0;
215-
}
216-
217-
out->offset += tlv->length;
218-
} else {
219-
out->frag = net_pkt_write(out->out_cpkt->pkt, out->frag,
220-
out->offset, &out->offset,
221-
tlv->length, value,
222-
BUF_ALLOC_TIMEOUT);
223-
if (!out->frag && out->offset == 0xffff) {
224-
/* TODO: Generate error? */
225-
return 0;
226-
}
208+
if (value != NULL && tlv->length > 0 && !insert) {
209+
out->frag = net_pkt_write(out->out_cpkt->pkt, out->frag,
210+
out->offset, &out->offset,
211+
tlv->length, value,
212+
BUF_ALLOC_TIMEOUT);
213+
if (!out->frag && out->offset == 0xffff) {
214+
/* TODO: Generate error? */
215+
return 0;
227216
}
228217
}
229218

0 commit comments

Comments
 (0)