Commit cc77f274 authored by Robert Lubos's avatar Robert Lubos Committed by Anas Nashif
Browse files

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: default avatarRobert Lubos <robert.lubos@nordicsemi.no>
parent 352ece1e
Loading
Loading
Loading
Loading
+3 −8
Original line number Diff line number Diff line
@@ -2170,8 +2170,6 @@ int net_context_recv(struct net_context *context,

#if defined(CONFIG_NET_CONTEXT_SYNC_RECV)
	if (!K_TIMEOUT_EQ(timeout, K_NO_WAIT)) {
		int ret;

		/* Make sure we have the lock, then the
		 * net_context_packet_received() callback will release the
		 * semaphore when data has been received.
@@ -2180,14 +2178,11 @@ int net_context_recv(struct net_context *context,

		k_mutex_unlock(&context->lock);

		ret = k_sem_take(&context->recv_data_wait, timeout);

		k_mutex_lock(&context->lock, K_FOREVER);

		if (ret == -EAGAIN) {
		if (k_sem_take(&context->recv_data_wait, timeout) == -EAGAIN) {
			ret = -ETIMEDOUT;
			goto unlock;
		}

		k_mutex_lock(&context->lock, K_FOREVER);
	}
#endif /* CONFIG_NET_CONTEXT_SYNC_RECV */