diff --git a/subsys/net/ip/net_context.c b/subsys/net/ip/net_context.c index c611f48b3fa292..9de988e54f8d94 100644 --- a/subsys/net/ip/net_context.c +++ b/subsys/net/ip/net_context.c @@ -709,24 +709,19 @@ int net_context_bind(struct net_context *context, const struct sockaddr *addr, return -EADDRNOTAVAIL; } - if (IS_ENABLED(CONFIG_NET_OFFLOAD) && - net_if_is_ip_offloaded(iface)) { - net_context_set_iface(context, iface); - - return net_offload_bind(iface, - context, - addr, - addrlen); - } - k_mutex_lock(&context->lock, K_FOREVER); - ret = 0; - net_context_set_iface(context, iface); net_sin6_ptr(&context->local)->sin6_family = AF_INET6; net_sin6_ptr(&context->local)->sin6_addr = ptr; + + if (IS_ENABLED(CONFIG_NET_OFFLOAD) && net_if_is_ip_offloaded(iface)) { + k_mutex_unlock(&context->lock); + return net_offload_bind(iface, context, addr, addrlen); + } + + ret = 0; if (addr6->sin6_port) { ret = check_used_port(context->proto, addr6->sin6_port, @@ -811,24 +806,19 @@ int net_context_bind(struct net_context *context, const struct sockaddr *addr, return -EADDRNOTAVAIL; } - if (IS_ENABLED(CONFIG_NET_OFFLOAD) && - net_if_is_ip_offloaded(iface)) { - net_context_set_iface(context, iface); - - return net_offload_bind(iface, - context, - addr, - addrlen); - } - k_mutex_lock(&context->lock, K_FOREVER); - ret = 0; - net_context_set_iface(context, iface); net_sin_ptr(&context->local)->sin_family = AF_INET; net_sin_ptr(&context->local)->sin_addr = ptr; + + if (IS_ENABLED(CONFIG_NET_OFFLOAD) && net_if_is_ip_offloaded(iface)) { + k_mutex_unlock(&context->lock); + return net_offload_bind(iface, context, addr, addrlen); + } + + ret = 0; if (addr4->sin_port) { ret = check_used_port(context->proto, addr4->sin_port,