diff --git a/net/udp/udp_conn.c b/net/udp/udp_conn.c index ec9f1be5426..3fe130a2165 100644 --- a/net/udp/udp_conn.c +++ b/net/udp/udp_conn.c @@ -816,6 +816,10 @@ int udp_bind(FAR struct udp_conn_s *conn, FAR const struct sockaddr *addr) } #endif + /* Interrupts must be disabled while access the UDP connection list */ + + net_lock(); + #ifdef CONFIG_NET_IPv4 #ifdef CONFIG_NET_IPv6 if (conn->domain == PF_INET) @@ -928,10 +932,6 @@ int udp_bind(FAR struct udp_conn_s *conn, FAR const struct sockaddr *addr) } else { - /* Interrupts must be disabled while access the UDP connection list */ - - net_lock(); - /* Is any other UDP connection already bound to this address * and port ? */ @@ -958,10 +958,9 @@ int udp_bind(FAR struct udp_conn_s *conn, FAR const struct sockaddr *addr) { ret = -EADDRINUSE; } - - net_unlock(); } + net_unlock(); return ret; }