Skip to content

Commit cc77f27

Browse files
rlubosnashif
authored andcommitted
net: context: Remove shadowing variable in net_context_recv()
Remove the shadowing ret variable and fix a bug that was related to its existence - the shadowing ret variable was assigned with -ETIMEDOUT which was supposed to be retuned by the function, but was not because the ret variable at the function scope was left intact. Also remove the unneded goto unlock; jump (assigning the error code is the last operation before unlocking the mutex anyway). Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
1 parent 352ece1 commit cc77f27

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

subsys/net/ip/net_context.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2170,8 +2170,6 @@ int net_context_recv(struct net_context *context,
21702170

21712171
#if defined(CONFIG_NET_CONTEXT_SYNC_RECV)
21722172
if (!K_TIMEOUT_EQ(timeout, K_NO_WAIT)) {
2173-
int ret;
2174-
21752173
/* Make sure we have the lock, then the
21762174
* net_context_packet_received() callback will release the
21772175
* semaphore when data has been received.
@@ -2180,14 +2178,11 @@ int net_context_recv(struct net_context *context,
21802178

21812179
k_mutex_unlock(&context->lock);
21822180

2183-
ret = k_sem_take(&context->recv_data_wait, timeout);
2184-
2185-
k_mutex_lock(&context->lock, K_FOREVER);
2186-
2187-
if (ret == -EAGAIN) {
2181+
if (k_sem_take(&context->recv_data_wait, timeout) == -EAGAIN) {
21882182
ret = -ETIMEDOUT;
2189-
goto unlock;
21902183
}
2184+
2185+
k_mutex_lock(&context->lock, K_FOREVER);
21912186
}
21922187
#endif /* CONFIG_NET_CONTEXT_SYNC_RECV */
21932188

0 commit comments

Comments
 (0)