Skip to content

Commit

Permalink
net: lwm2m: Check result when sending messages
Browse files Browse the repository at this point in the history
`lwm2m_send_message_async` returns critical errors which are not handled in
many cases. The function can return -ENOMEM, -EPERM or other error codes
from functions called.

Signed-off-by: Marc Lasch <[email protected]>
  • Loading branch information
mlasch committed Jan 29, 2025
1 parent 5a40e49 commit d4cedc8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
7 changes: 6 additions & 1 deletion subsys/net/lib/lwm2m/lwm2m_message_handling.c
Original file line number Diff line number Diff line change
Expand Up @@ -2912,7 +2912,12 @@ void lwm2m_udp_receive(struct lwm2m_ctx *client_ctx, uint8_t *buf, uint16_t buf_
}

client_ctx->processed_req = NULL;
lwm2m_send_message_async(msg);
r = lwm2m_send_message_async(msg);
if (r < 0) {
LOG_ERR("Failed to send response (err: %d)", r);
lwm2m_reset_message(msg, true);
return;
}
} else {
LOG_DBG("No handler for response");
}
Expand Down
17 changes: 14 additions & 3 deletions subsys/net/lib/lwm2m/lwm2m_rd_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,11 @@ static int sm_send_bootstrap_registration(void)
LOG_DBG("Register ID with bootstrap server as '%s'",
query_buffer);

lwm2m_send_message_async(msg);
ret = lwm2m_send_message_async(msg);
if (ret < 0) {
LOG_ERR("Failed to send bootstrap message (err: %d)", ret);
goto cleanup;
}

return 0;

Expand Down Expand Up @@ -987,7 +991,10 @@ static int sm_send_registration(bool send_obj_support_data,
}
}

lwm2m_send_message_async(msg);
ret = lwm2m_send_message_async(msg);
if (ret < 0) {
goto cleanup;
}

/* log the registration attempt */
LOG_DBG("registration sent [%s]",
Expand Down Expand Up @@ -1259,7 +1266,11 @@ static int sm_do_deregister(void)

LOG_INF("Deregister from '%s'", client.server_ep);

lwm2m_send_message_async(msg);
ret = lwm2m_send_message_async(msg);
if (ret < 0) {
LOG_ERR("Failed to send deregistration message (err:%d).", ret);
goto cleanup;
}

set_sm_state(ENGINE_DEREGISTER_SENT);
return 0;
Expand Down

0 comments on commit d4cedc8

Please sign in to comment.