From 324446bbba09db9e49204ee9dcb4df7a769e01b5 Mon Sep 17 00:00:00 2001 From: Kian Karas Date: Thu, 8 Feb 2024 14:32:20 +0100 Subject: [PATCH] net/udp: fix net_[un]lock() in udp_bind net_unlock() called without a previous call to net_lock(). Error introduced by b10d6be17a6 --- net/udp/udp_conn.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) 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; }