Skip to content

Commit 6150da7

Browse files
rluboscarlescufi
authored andcommitted
[nrf fromlist] net: openthread: Fix ignored return values in OT utils
Upstream PR #: 88359 Do not ignore return values of OT functions registering IPv6 addresses. As this is called from the net_mgmt callback context, which returns void, there's not much that can be done, other than logging the error. To simplify the logging code and avoid the need to use extra buffer, use net_sprint_ipv6_addr() networking utility function within the log message to convert binary address to string. Signed-off-by: Robert Lubos <[email protected]>
1 parent 4034b0f commit 6150da7

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

subsys/net/l2/openthread/openthread_utils.c

+15-12
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ LOG_MODULE_DECLARE(net_l2_openthread, CONFIG_OPENTHREAD_L2_LOG_LEVEL);
1414
#include <openthread/ip6.h>
1515
#include <openthread/thread.h>
1616

17+
#include "net_private.h"
1718
#include "openthread_utils.h"
1819

1920
#define ALOC16_MASK 0xfc
@@ -167,6 +168,7 @@ void add_ipv6_addr_to_ot(struct openthread_context *context,
167168
struct otNetifAddress addr = { 0 };
168169
struct net_if_ipv6 *ipv6;
169170
struct net_if_addr *if_addr = NULL;
171+
otError error;
170172
int i;
171173

172174
/* IPv6 struct should've already been allocated when we get an
@@ -214,33 +216,34 @@ void add_ipv6_addr_to_ot(struct openthread_context *context,
214216
}
215217

216218
openthread_api_mutex_lock(context);
217-
otIp6AddUnicastAddress(context->instance, &addr);
219+
error = otIp6AddUnicastAddress(context->instance, &addr);
218220
openthread_api_mutex_unlock(context);
219221

220-
if (CONFIG_OPENTHREAD_L2_LOG_LEVEL == LOG_LEVEL_DBG) {
221-
char buf[NET_IPV6_ADDR_LEN];
222-
223-
NET_DBG("Added %s",
224-
net_addr_ntop(AF_INET6, &addr.mAddress, buf, sizeof(buf)));
222+
if (error != OT_ERROR_NONE) {
223+
NET_ERR("Failed to add IPv6 unicast address %s [%d]",
224+
net_sprint_ipv6_addr(addr6), error);
225+
} else {
226+
NET_DBG("Added %s", net_sprint_ipv6_addr(addr6));
225227
}
226228
}
227229

228230
void add_ipv6_maddr_to_ot(struct openthread_context *context,
229231
const struct in6_addr *addr6)
230232
{
231233
struct otIp6Address addr;
234+
otError error;
232235

233236
memcpy(&addr, addr6, sizeof(addr));
234237

235238
openthread_api_mutex_lock(context);
236-
otIp6SubscribeMulticastAddress(context->instance, &addr);
239+
error = otIp6SubscribeMulticastAddress(context->instance, &addr);
237240
openthread_api_mutex_unlock(context);
238241

239-
if (CONFIG_OPENTHREAD_L2_LOG_LEVEL == LOG_LEVEL_DBG) {
240-
char buf[NET_IPV6_ADDR_LEN];
241-
242-
NET_DBG("Added multicast %s",
243-
net_addr_ntop(AF_INET6, &addr, buf, sizeof(buf)));
242+
if (error != OT_ERROR_NONE) {
243+
NET_ERR("Failed to add IPv6 multicast address %s [%d]",
244+
net_sprint_ipv6_addr(addr6), error);
245+
} else {
246+
NET_DBG("Added %s", net_sprint_ipv6_addr(addr6));
244247
}
245248
}
246249

0 commit comments

Comments
 (0)