Skip to content

Commit 06c6605

Browse files
committed
[nrf fromlist] net: openthread: Add missing error checks
Upstream PR #: 88166 Some OpenThread functions were called without verifying the return value, which not only is not the best practice, but also could lead to build warnings with llvm. This commit fixes it. Signed-off-by: Robert Lubos <[email protected]>
1 parent 80ef797 commit 06c6605

File tree

1 file changed

+56
-12
lines changed

1 file changed

+56
-12
lines changed

subsys/net/l2/openthread/openthread.c

Lines changed: 56 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,11 @@ static void ot_joiner_start_handler(otError error, void *context)
329329
switch (error) {
330330
case OT_ERROR_NONE:
331331
NET_INFO("Join success");
332-
otThreadSetEnabled(ot_context->instance, true);
332+
error = otThreadSetEnabled(ot_context->instance, true);
333+
if (error != OT_ERROR_NONE) {
334+
NET_ERR("Failed to start the OpenThread network [%d]", error);
335+
}
336+
333337
break;
334338
default:
335339
NET_ERR("Join failed [%d]", error);
@@ -430,7 +434,11 @@ int openthread_start(struct openthread_context *ot_context)
430434
goto exit;
431435
}
432436

433-
otIp6SetEnabled(ot_context->instance, true);
437+
error = otIp6SetEnabled(ot_context->instance, true);
438+
if (error != OT_ERROR_NONE) {
439+
NET_ERR("Failed to set %s [%d]", "IPv6 support", error);
440+
goto exit;
441+
}
434442

435443
/* Sleepy End Device specific configuration. */
436444
if (IS_ENABLED(CONFIG_OPENTHREAD_MTD_SED)) {
@@ -441,8 +449,17 @@ int openthread_start(struct openthread_context *ot_context)
441449
*/
442450
ot_mode.mRxOnWhenIdle = false;
443451

444-
otThreadSetLinkMode(ot_context->instance, ot_mode);
445-
otLinkSetPollPeriod(ot_context->instance, OT_POLL_PERIOD);
452+
error = otThreadSetLinkMode(ot_context->instance, ot_mode);
453+
if (error != OT_ERROR_NONE) {
454+
NET_ERR("Failed to set %s [%d]", "link mode", error);
455+
goto exit;
456+
}
457+
458+
error = otLinkSetPollPeriod(ot_context->instance, OT_POLL_PERIOD);
459+
if (error != OT_ERROR_NONE) {
460+
NET_ERR("Failed to set %s [%d]", "poll period", error);
461+
goto exit;
462+
}
446463
}
447464

448465
/* Configure Child Supervision and MLE Child timeouts. */
@@ -477,16 +494,39 @@ int openthread_start(struct openthread_context *ot_context)
477494
otExtendedPanId xpanid;
478495
otNetworkKey networkKey;
479496

480-
otThreadSetNetworkName(ot_instance, OT_NETWORK_NAME);
481-
otLinkSetChannel(ot_instance, OT_CHANNEL);
482-
otLinkSetPanId(ot_instance, OT_PANID);
497+
error = otThreadSetNetworkName(ot_instance, OT_NETWORK_NAME);
498+
if (error != OT_ERROR_NONE) {
499+
NET_ERR("Failed to set %s [%d]", "network name", error);
500+
goto exit;
501+
}
502+
503+
error = otLinkSetChannel(ot_instance, OT_CHANNEL);
504+
if (error != OT_ERROR_NONE) {
505+
NET_ERR("Failed to set %s [%d]", "channel", error);
506+
goto exit;
507+
}
508+
509+
error = otLinkSetPanId(ot_instance, OT_PANID);
510+
if (error != OT_ERROR_NONE) {
511+
NET_ERR("Failed to set %s [%d]", "PAN ID", error);
512+
goto exit;
513+
}
514+
483515
net_bytes_from_str(xpanid.m8, 8, (char *)OT_XPANID);
484-
otThreadSetExtendedPanId(ot_instance, &xpanid);
516+
error = otThreadSetExtendedPanId(ot_instance, &xpanid);
517+
if (error != OT_ERROR_NONE) {
518+
NET_ERR("Failed to set %s [%d]", "ext PAN ID", error);
519+
goto exit;
520+
}
485521

486522
if (strlen(OT_NETWORKKEY)) {
487523
net_bytes_from_str(networkKey.m8, OT_NETWORK_KEY_SIZE,
488524
(char *)OT_NETWORKKEY);
489-
otThreadSetNetworkKey(ot_instance, &networkKey);
525+
error = otThreadSetNetworkKey(ot_instance, &networkKey);
526+
if (error != OT_ERROR_NONE) {
527+
NET_ERR("Failed to set %s [%d]", "network key", error);
528+
goto exit;
529+
}
490530
}
491531
}
492532

@@ -533,7 +573,7 @@ static int openthread_init(struct net_if *iface)
533573
.name = "openthread",
534574
.no_yield = true,
535575
};
536-
otError err;
576+
otError err = OT_ERROR_NONE;
537577

538578
NET_DBG("openthread_init");
539579

@@ -556,7 +596,11 @@ static int openthread_init(struct net_if *iface)
556596
}
557597

558598
if (IS_ENABLED(CONFIG_OPENTHREAD_COPROCESSOR)) {
559-
otPlatUartEnable();
599+
err = otPlatUartEnable();
600+
if (err != OT_ERROR_NONE) {
601+
NET_ERR("Failed to enable UART: [%d]", err);
602+
}
603+
560604
otNcpHdlcInit(ot_context->instance, ncp_hdlc_send);
561605
} else {
562606
otIp6SetReceiveFilterEnabled(ot_context->instance, true);
@@ -604,7 +648,7 @@ static int openthread_init(struct net_if *iface)
604648

605649
(void)k_work_submit_to_queue(&ot_context->work_q, &ot_context->api_work);
606650

607-
return 0;
651+
return (err == OT_ERROR_NONE) ? 0 : -EIO;
608652
}
609653

610654
void ieee802154_init(struct net_if *iface)

0 commit comments

Comments
 (0)